Commits

Micah Ransdell committed d5123a5

add boilerplate for page scope

  • Participants
  • Parent commits ba2b366

Comments (0)

Files changed (1)

twitter-lists.user.js

 // @include   https://*.twitter.com/*
 // ==/UserScript==
 
+if ('undefined' == typeof __PAGE_SCOPE_RUN__) {
+  (function page_scope_runner() {
+    // If we're _not_ already running in the page, grab the full source
+    // of this script.
+    var my_src = "(" + page_scope_runner.caller.toString() + ")();";
+
+    // Create a script node holding this script, plus a marker that lets us
+    // know we are running in the page scope (not the Greasemonkey sandbox).
+    // Note that we are intentionally *not* scope-wrapping here.
+    var script = document.createElement('script');
+    script.setAttribute("type", "text/javascript");
+    script.textContent = "var __PAGE_SCOPE_RUN__ = true;\n" + my_src;
+
+    // Insert the script node into the page, so it will run. Use setTimeout to force execution "outside" of
+    // the user script scope completely.
+    setTimeout(function() {document.body.appendChild(script);
+        }, 0);
+  })();
+
+  // Stop running, because we know Greasemonkey actually runs us in
+  // an anonymous wrapper.
+  return;
+}
 
 $(function(){
     var listLink = $('[data-name="lists"] a');