2

I'm building a UserScript and I try to block an external JS script (ckeditor.js) loaded from the HTML code.

It should be easy with "beforescriptexecute" but there is a catch: The site use RocketLoader which is a sort of cache for js scripts.

Let me show you the HTML code and the custom Script tag:

<script type="text/rocketscript" data-rocketsrc="ckeditor/ckeditor.js"></script>

Since the tag is "custom" "beforescriptexecute" event is not able to stop ckeditor.js from running.

Do you know how I can block this script only (from my userscript) ?

7
  • So this is an Addon you want to disable, using JavaScript? Commented Aug 17, 2016 at 23:56
  • No I can disable the script using addon but I want to do it from a Userscript/Greasemonkey Script. Commented Aug 18, 2016 at 0:31
  • define a non-configurable global in the way of whatever the script uses/needs; maybe Object.defineProperty(window, "CKEditor",{value: {}})... this will prevent the script from working no matter how it's loaded Commented Aug 18, 2016 at 1:44
  • @dandavis Could you give me an example ? I've tried but it don't seem to work. Here's the source page: pagebin.com Commented Aug 18, 2016 at 2:31
  • the global is CKEDITOR; i guessed wrong. Commented Aug 18, 2016 at 2:36

2 Answers 2

2

Try something like:

document.querySelector("script[data-rocketsrc='ckeditor/ckeditor.js']").remove()
Sign up to request clarification or add additional context in comments.

2 Comments

Sadly it did not work, here's the web page in question: pagebin.com
I upvoted this because it's a good idea, but shame on you man, it really doesn't work.
0

There's multiple ways to go around this. I will mention them:

  • Destroy ckeditor after page loads
  • Enable Toggle sourcecode button for ckeditor (yes, it is possible)
  • Tamper with cloudflare's cache

I already did those first two, so I decided to try the third option. If you print `localStorage contents in console, you can see how this cache works:

image description

For every script, there's an entry. The JSON structure looks like this:

{
    "url": "http://pagebin.com/ckeditor/ckeditor.js",
    "contents": "/*script code here*/",
    "version": "0.1.33",
    "ctime": 1471875453444,
    "stime": 1471875453444,
    "ttl": 604800000,
    "meta": [
        null,
        null,
        null,
        "200"
    ]
}

All you need is to set the contents to empty string:

// ==UserScript==
// @name        Disable cloudflare cached script
// @namespace   util
// @description Prevents script from being used from cache. It can still be loaded normally.
// @include     http://pagebin.com/
// @version     1
// @grant       none
// @run-at      document-start
// @author       http://stackoverflow.com/a/39082174/607407
// ==/UserScript==
var ckeditorURL = "CLOUDFLARE::http://pagebin.com/ckeditor/ckeditor.js";


var json = JSON.parse(localStorage[ckeditorURL]);
json.contents = "// nothing here, move along";
localStorage[ckeditorURL] = JSON.stringify(json);

Result:

image description

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.