Skip to content

Instantly share code, notes, and snippets.

@jpcaparas
Last active February 14, 2024 19:49
Show Gist options
  • Save jpcaparas/e8257fca97e2fad44a43c34668810244 to your computer and use it in GitHub Desktop.
Save jpcaparas/e8257fca97e2fad44a43c34668810244 to your computer and use it in GitHub Desktop.
Tampermonkey: Load an external script and CSS
// ==UserScript==
// @name HackerNews
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://news.ycombinator.com/
// @require https://bennettfeely.com/ztext/js/ztext.min.js
// @resource REMOTE_CSS http://127.0.0.1:8080/style.css
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_addStyle
// ==/UserScript==
(function() {
'use strict';
// Load remote JS
GM_xmlhttpRequest({
method : "GET",
// from other domain than the @match one (.org / .com):
url : "https://bennettfeely.com/ztext/js/ztext.min.js",
onload : (ev) =>
{
let e = document.createElement('script');
e.innerText = ev.responseText;
document.head.appendChild(e);
}
});
// Load remote CSS
// @see https://github.com/Tampermonkey/tampermonkey/issues/835
const myCss = GM_getResourceText("REMOTE_CSS");
GM_addStyle(myCss);
// document.querySelector('.hnname').setAttribute('data-z', true)
// document.querySelector('.hnname').setAttribute('data-z-layers', 3);
setTimeout(function() {
var ztxt = new Ztextify(".hnname", {
depth: "30px",
layers: 8,
fade: true,
direction: "forwards",
event: "pointer",
eventRotation: "35deg"
});
}, 3000);
})();
@Tao309
Copy link

Tao309 commented Mar 31, 2023

let e = document.createElement('script');
e.type = 'module';
e.innerText = ev.responseText;
document.head.appendChild(e);

@iamqiz
Copy link

iamqiz commented Jan 1, 2024

thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment