redo userscript
This commit is contained in:
parent
7b0658781a
commit
1fcbe56133
|
@ -1,8 +0,0 @@
|
|||
// ==UserScript==
|
||||
// @name MZTE CSS
|
||||
// @version 0.1.0
|
||||
// @description Injects some CSS into every page
|
||||
// @author LordMZTE
|
||||
// @include *
|
||||
// @run-at document-start
|
||||
// ==/UserScript==
|
|
@ -1,7 +0,0 @@
|
|||
import js.Browser;
|
||||
|
||||
function main() {
|
||||
var elem = Browser.document.createStyleElement();
|
||||
elem.innerHTML = Macro.fileContent("assets/style.css");
|
||||
Browser.document.addEventListener("DOMContentLoaded", () -> Browser.document.body.appendChild(elem));
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
// ==UserScript==
|
||||
// @name MZTE
|
||||
// @version 0.1.0
|
||||
// @description Random stuff
|
||||
// @author LordMZTE
|
||||
// @include *
|
||||
// @run-at document-start
|
||||
// @grant GM_registerMenuCommand
|
||||
// @grant GM_getValue
|
||||
// @grant GM_setValue
|
||||
// ==/UserScript==
|
|
@ -0,0 +1,15 @@
|
|||
.tampermonkey_mzte_notif {
|
||||
position: fixed;
|
||||
z-index: 100000;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
font-family: "Iosevka Nerd Font", monospace;
|
||||
color: #cdd6f4;
|
||||
font-size: 20px;
|
||||
background-color: #1e1e2e;
|
||||
margin-right: 20px;
|
||||
margin-bottom: 20px;
|
||||
border-style: solid;
|
||||
border-width: 2px;
|
||||
border-color: #f38ba8;
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
import js.html.MouseEvent;
|
||||
|
||||
@:native("") extern class GM {
|
||||
@:native("GM_registerMenuCommand")
|
||||
static function registerMenuCommand(label:String, cb:MouseEvent->Void):Void;
|
||||
|
||||
@:native("GM_getValue")
|
||||
static function getValue(key:String, ?defaultValue:Dynamic):Dynamic;
|
||||
|
||||
@:native("GM_setValue")
|
||||
static function setValue(key:String, value:Dynamic):Void;
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
import js.Browser;
|
||||
|
||||
function main() {
|
||||
var ownStyle = Browser.document.createStyleElement();
|
||||
ownStyle.innerHTML = Macro.fileContent("assets/own_style.css");
|
||||
|
||||
var style = Browser.document.createStyleElement();
|
||||
style.innerHTML = Macro.fileContent("assets/style.css");
|
||||
|
||||
Browser.document.addEventListener("DOMContentLoaded", () -> {
|
||||
Browser.document.body.appendChild(ownStyle);
|
||||
|
||||
if (!actions.ToggleStyleAction.blacklist.has(Browser.window.location.hostname)) {
|
||||
Browser.document.body.appendChild(style);
|
||||
}
|
||||
});
|
||||
|
||||
new actions.InfoAction().register();
|
||||
new actions.ToggleStyleAction(style).register();
|
||||
new actions.ClearCookiesAction().register();
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
import js.Browser;
|
||||
import js.html.Element;
|
||||
|
||||
function show(text:String):Void {
|
||||
var span = Browser.document.createSpanElement();
|
||||
span.innerText = text;
|
||||
showElem(span);
|
||||
}
|
||||
|
||||
function showElem(elem:Element):Void {
|
||||
var div = Browser.document.createDivElement();
|
||||
div.className = "tampermonkey_mzte_notif";
|
||||
div.appendChild(elem);
|
||||
|
||||
Browser.document.body.appendChild(div);
|
||||
Browser.window.setTimeout(div.remove, 5000);
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package actions;
|
||||
|
||||
import js.html.MouseEvent;
|
||||
|
||||
abstract class Action {
|
||||
var label(get, never):String;
|
||||
|
||||
public function register():Void {
|
||||
GM.registerMenuCommand(this.label, this.call);
|
||||
};
|
||||
|
||||
abstract function get_label():String;
|
||||
abstract function call(ev: MouseEvent):Void;
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package actions;
|
||||
|
||||
import js.lib.Date;
|
||||
import js.Browser;
|
||||
import js.html.MouseEvent;
|
||||
|
||||
class ClearCookiesAction extends Action {
|
||||
public static var cookies(get, never):Array<String>;
|
||||
|
||||
public function new() {}
|
||||
|
||||
function get_label():String {
|
||||
return "Clear Cookies";
|
||||
}
|
||||
|
||||
function call(ev:MouseEvent) {
|
||||
var cks = cookies;
|
||||
|
||||
var now = new Date().toUTCString();
|
||||
|
||||
for (cookie in cks) {
|
||||
var key = cookie.split("=")[0];
|
||||
Browser.document.cookie = '$key=;expires=$now;path=/';
|
||||
}
|
||||
|
||||
if (cks.length == 0) {
|
||||
Notifications.show("No Cookies to Delete.");
|
||||
return;
|
||||
}
|
||||
|
||||
var notifElem = Browser.document.createDivElement();
|
||||
|
||||
var labelElem = Browser.document.createParagraphElement();
|
||||
labelElem.innerText = "Deleted These Cookies:";
|
||||
notifElem.appendChild(labelElem);
|
||||
|
||||
var listElem = Browser.document.createUListElement();
|
||||
listElem.setAttribute("style", "list-style-position: inside;");
|
||||
for (cookie in cks) {
|
||||
var liElem = Browser.document.createLIElement();
|
||||
liElem.innerText = cookie.split("=")[0];
|
||||
|
||||
listElem.appendChild(liElem);
|
||||
}
|
||||
notifElem.append(listElem);
|
||||
|
||||
Notifications.showElem(notifElem);
|
||||
}
|
||||
|
||||
static function get_cookies():Array<String> {
|
||||
return Browser.document.cookie
|
||||
.split(";")
|
||||
.map(StringTools.trim)
|
||||
.filter(s -> s.length != 0);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
package actions;
|
||||
|
||||
import js.Browser;
|
||||
import js.html.MouseEvent;
|
||||
|
||||
using js.lib.HaxeIterator;
|
||||
|
||||
class InfoAction extends Action {
|
||||
public function new() {}
|
||||
|
||||
function get_label():String {
|
||||
return "Info";
|
||||
}
|
||||
|
||||
function call(ev:MouseEvent) {
|
||||
var divElem = Browser.document.createDivElement();
|
||||
divElem.setAttribute("style", "overflow-y:scroll;height:500px;");
|
||||
|
||||
{
|
||||
var labelElem = Browser.document.createParagraphElement();
|
||||
labelElem.innerText = '${ClearCookiesAction.cookies.length} cookies';
|
||||
divElem.appendChild(labelElem);
|
||||
}
|
||||
|
||||
{
|
||||
var labelElem = Browser.document.createParagraphElement();
|
||||
labelElem.innerText = "Style Blacklist:";
|
||||
divElem.appendChild(labelElem);
|
||||
|
||||
var listElem = Browser.document.createUListElement();
|
||||
for (domain in ToggleStyleAction.blacklist.keys()) {
|
||||
var liElem = Browser.document.createLIElement();
|
||||
liElem.innerText = domain;
|
||||
listElem.appendChild(liElem);
|
||||
}
|
||||
divElem.appendChild(listElem);
|
||||
}
|
||||
|
||||
Notifications.showElem(divElem);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
package actions;
|
||||
|
||||
import js.lib.Set;
|
||||
import js.Browser;
|
||||
import js.html.StyleElement;
|
||||
import js.html.MouseEvent;
|
||||
|
||||
class ToggleStyleAction extends Action {
|
||||
public static var blacklist(get, set):Set<String>;
|
||||
|
||||
static function get_blacklist():Set<String> {
|
||||
var arr:Array<String> = GM.getValue("domainBlacklist", []);
|
||||
return new Set(arr);
|
||||
}
|
||||
|
||||
static function set_blacklist(value:Set<String>):Set<String> {
|
||||
GM.setValue("domainBlacklist", [for (v in value) v]);
|
||||
return value;
|
||||
}
|
||||
|
||||
var styleElem:StyleElement;
|
||||
|
||||
public function new(style_elem:StyleElement) {
|
||||
this.styleElem = style_elem;
|
||||
}
|
||||
|
||||
function get_label():String {
|
||||
return "Toggle Style";
|
||||
}
|
||||
|
||||
function call(ev:MouseEvent) {
|
||||
var bl = blacklist;
|
||||
if (this.styleElem.parentElement == null) {
|
||||
Browser.document.body.appendChild(this.styleElem);
|
||||
bl.delete(Browser.window.location.hostname);
|
||||
Notifications.show("Style Enabled");
|
||||
} else {
|
||||
this.styleElem.remove();
|
||||
bl.add(Browser.window.location.hostname);
|
||||
Notifications.show("Style Disabled");
|
||||
}
|
||||
blacklist = bl;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue