Skip to content

Instantly share code, notes, and snippets.

@machsix
Forked from cking/owo.whats-th.is.user.js
Created April 6, 2019 09:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save machsix/d86598442523e0a8c55ff65bab72230f to your computer and use it in GitHub Desktop.
Save machsix/d86598442523e0a8c55ff65bab72230f to your computer and use it in GitHub Desktop.
owo.whats-th.is.user.js
// ==UserScript==
// @name OwO, whats this :D
// @namespace http://tampermonkey.net/
// @version 0.2
// @description try to take over the world!
// @author Christopher König
// @include *
// @connect api.awau.moe
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_xmlhttpRequest
// @grant GM_setClipboard
// @grant GM_notification
// ==/UserScript==
(function() {
'use strict';
function shim_GM_notification () {
if (typeof GM_notification === "function") {
return;
}
window.GM_notification = function (ntcOptions) {
checkPermission ();
function checkPermission () {
if (Notification.permission === "granted") {
fireNotice ();
}
else if (Notification.permission === "denied") {
alert ("User has denied notifications for this page/site!");
return;
}
else {
Notification.requestPermission ( function (permission) {
console.log ("New permission: ", permission);
checkPermission ();
} );
}
}
function fireNotice () {
if ( ! ntcOptions.title) {
console.log ("Title is required for notification");
return;
}
if (ntcOptions.text && ! ntcOptions.body) {
ntcOptions.body = ntcOptions.text;
}
var ntfctn = new Notification (ntcOptions.title, ntcOptions);
if (ntcOptions.onclick) {
ntfctn.onclick = ntcOptions.onclick;
}
if (ntcOptions.timeout) {
setTimeout ( function() {
ntfctn.close ();
}, ntcOptions.timeout);
}
}
}
}
shim_GM_notification();
GM_registerMenuCommand("Set token", () => {
const token = window.prompt("Set your token");
if (token) {
GM_setValue("token", token);
}
}, "t");
GM_registerMenuCommand("Set custom shortener base url", () => {
const baseurl = window.prompt("Set your base url");
GM_setValue("baseurl", baseurl);
}, "b");
GM_registerMenuCommand("Copy Shortlink", () => {
const url = encodeURIComponent(window.location.href);
const token = GM_getValue("token", "");
const baseUrl = GM_getValue("baseurl", "");
const xhr = GM_xmlhttpRequest({
method: "GET",
url: `https://api.awau.moe/shorten/polr?key=${token}&action=shorten&url=${url}`,
onload: res => {
try {
JSON.parse(res.responseText);
GM_notification("Failed to create shortlink!");
} catch(ex) {
const url = baseUrl? res.responseText.replace("awau.moe", baseUrl): res.responseText;
GM_setClipboard(url, "text");
GM_notification(url, "Shortlink created");
}
}
});
}, "c");
// Your code here...
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment