Last active
May 25, 2024 15:39
-
-
Save atnbueno/006dbcdb5a39c6994c1031705642cd5d to your computer and use it in GitHub Desktop.
My starting point for Violentmonkey userscripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Website tweaks | |
// @version 1.4 | |
// @author Antonio Bueno <[email protected]> | |
// @namespace userscripts.atnbueno.com | |
// @match http://www.example.com/* | |
// @require https://cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js | |
// @require https://cdn.jsdelivr.net/npm/toastify-js | |
// @resource toastifyCSS https://cdn.jsdelivr.net/npm/toastify-js/src/toastify.min.css | |
// @grant GM_addStyle | |
// @grant GM_getResourceText | |
// ==/UserScript== | |
(function () { | |
"use strict"; | |
/* | |
* DOM manipulations courtesy of jQuery | |
*/ | |
// Modificacions are applied once the DOM has been build (images may be still loading) | |
$(document).ready(function () { | |
// Makes clear that the script is running and its version | |
notification(GM.info.script.name + " " + GM.info.script.version, "hello", 3); | |
// Technical info to console | |
console.log(GM.info); | |
/* Your code here */ | |
}); | |
/* | |
* Notifications courtesy of Toastify JS (see https://apvarun.github.io/toastify-js/) | |
*/ | |
GM_addStyle(GM_getResourceText("toastifyCSS") + ` | |
div.toastify { margin: inherit; padding-bottom: 20px; width: inherit; font-family: | |
-apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif } | |
`); | |
function notification(message, type = "info", timeout = 5) { | |
// The "type" parameter accepts four values: "info", "warning", "error" and "hello" | |
// The "timeout" parameter is expressed in seconds although Toastify uses milliseconds | |
var color, icon; | |
switch (type) { | |
case "warning": color = "rgba(201, 201, 0, 0.8)"; icon = "⚠️"; break; | |
case "error": color = "rgba(201, 51, 51, 0.8)"; icon = "🛑"; break; | |
case "hello": color = "rgba(51, 153, 51, 0.8)"; icon = "👋🏼"; break; | |
default: color = "rgba(51, 51, 153, 0.8)"; icon = "ℹ️\uFE0F "; | |
} | |
Toastify({ text: icon + " " + message, duration: timeout * 1000, gravity: "bottom", style: { background: color } }).showToast(); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment