0

Is it possible to replace HTML, JS and CSS files with Tampermonkey?

These files would be hosted on a server and would just replace the files I want like the index.html, a JS files and the main styles CSS. I could only find how to replace functions of a JS files but not how to replace a file...

This is the only thing i found: (but it's not working)

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        http://xxx.xx/
// @grant        none
// ==/UserScript==

for (var i = document.styleSheets.length - 1; i >= 0; i--) {
    document.styleSheets[i].disabled = true;
}

var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'http://xx.com/xx/x/x.x.x/xxxx.css';
document.getElementsByTagName("head")[0].appendChild(link);

edit: this works for the css file...but the index.html is not linking to it...

Maybe its not possible :)

Thanks for any help.

user1723097
  • 109
  • 1
  • 7
  • Browsers work with HTML and CSS and, essentially, javascript. Those are requirements. There are no alternatives. I don't know what tampermonkey is but it doesn't matter. Nothing can take the place of HTML or CSS in the browser. – Rob Nov 14 '15 at 00:59
  • 1
    Yeah sure, sorry i think you don't understand...i have a website, that i want to load alternativ files in it with tampermonkey... so i have my modified html css and js files that i want the website to load on... – user1723097 Nov 14 '15 at 01:03
  • Try putting a window.open call before you create your "var link = ..." line – Mike Horstmann Nov 14 '15 at 01:14

2 Answers2

1

(http://www.htmlgoodies.com/beyond/javascript/javascript-dynamic-document-creation-in-new-windows.html)

Try looking at the link and check out (in order) the topics "Cross-Writing Variables" and "Cross-Window HTML." If you do that, you'll understand more about what tampermonkey is doing within the script snippet you're using above and also you should be able to see how to set your existing html document to the default html document that loads.

One side note, there's better ways to perform this process if you have access to install serving languages or frameworks to your server.

Mike Horstmann
  • 580
  • 2
  • 9
1

If you are using Chromium with extension support check out Resource Override. It does what you want. JS, CSS, HTML, also Modifying Response headers. Can redirected to another URL whether it's remote or localhost, or store the code directly in the plugin.

KKthebeast
  • 11
  • 1