浏览代码

force-reload when pg in full-url mode

Raanan Weber 5 年之前
父节点
当前提交
b340c37bea
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      Playground/js/main.js

+ 7 - 1
Playground/js/main.js

@@ -693,7 +693,9 @@ class Main {
                                         newPG = "";
                                         break;
                                 }
-                                window.location.href = location.protocol + "//" + location.host + location.pathname + "#" + newPG;
+                                // reset pathname if it is a 'pg/' location
+                                const pathname = location.pathname.match(/\/pg\//) ? '/' : location.pathname;
+                                window.location.href = location.protocol + "//" + location.host + pathname + "#" + newPG;
                             } else if (query.indexOf("=") === -1) {
                                 this.loadScript("scripts/" + query + ".js", query);
                             } else if (query.indexOf('pg=') === -1 && !location.pathname.match(/\/pg\//)) {
@@ -717,6 +719,10 @@ class Main {
         // Check if safe mode is on, and ask if it is
         if (!this.checkSafeMode("Are you sure you want to create a new playground?")) return;
         location.hash = "";
+        if(location.pathname.indexOf('pg/') !== -1) {
+            // reload to create a new pg if in full-path playground mode.
+            window.location.pathname = '';
+        }
         this.currentSnippetToken = null;
         this.currentSnippetTitle = null;
         this.currentSnippetDescription = null;