[web] add my userscripts

This commit is contained in:
Dmytro Meleshko 2021-05-08 15:53:40 +03:00
parent 1b38e41eec
commit 50440e632a
8 changed files with 164 additions and 0 deletions

View File

@ -0,0 +1 @@
[Tampermonkey](https://www.tampermonkey.net/) ([Firefox extension](https://addons.mozilla.org/en-US/firefox/addon/tampermonkey/), [Chrome extension](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo)) is recommended for loading these as it supports installing and updating userscripts from a remote URL.

View File

@ -0,0 +1,32 @@
// ==UserScript==
// @name GitHub icon vertical alignment fix
// @version 1
// @grant none
// @match https://github.com/*
// @match https://gist.github.com/*
// @run-at document-start
// ==/UserScript==
(() => {
'use strict';
function addStylesheet() {
let style = document.createElement('style');
style.append(
//
'.btn-sm .octicon {\n',
' vertical-align: middle;\n',
'}\n',
);
document.head.appendChild(style);
}
if (document.readyState !== 'loading') {
addStylesheet();
} else {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'loading') return;
addStylesheet();
});
}
})();

View File

@ -0,0 +1,34 @@
// ==UserScript==
// @name GitHub line-height
// @version 1
// @grant none
// @match https://github.com/*
// @match https://gist.github.com/*
// @run-at document-start
// ==/UserScript==
(() => {
'use strict';
const LINE_HEIGHT = '1.2';
function addStylesheet() {
let style = document.createElement('style');
style.append(
'.blob-num, .blob-code, .markdown-body .highlight pre, .markdown-body pre, \n',
'.cm-s-github-light .CodeMirror-lines, textarea.file-editor-textarea {\n',
` line-height: ${LINE_HEIGHT};\n`,
'}\n',
);
document.head.appendChild(style);
}
if (document.readyState !== 'loading') {
addStylesheet();
} else {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'loading') return;
addStylesheet();
});
}
})();

View File

@ -0,0 +1,34 @@
// ==UserScript==
// @name GitHub tab size 4
// @version 1
// @grant none
// @match https://github.com/*
// @match https://gist.github.com/*
// @run-at document-start
// ==/UserScript==
(() => {
'use strict';
const TAB_SIZE = '4';
function addStylesheet() {
let style = document.createElement('style');
style.append(
'* {\n',
` -moz-tab-size: ${TAB_SIZE} !important;\n`,
` tab-size: ${TAB_SIZE} !important;\n`,
'}\n',
);
document.head.appendChild(style);
}
if (document.readyState !== 'loading') {
addStylesheet();
} else {
document.addEventListener('readystatechange', () => {
if (document.readyState === 'loading') return;
addStylesheet();
});
}
})();

View File

@ -0,0 +1,16 @@
// ==UserScript==
// @name steamcommunity.com linkfilter disabler
// @version 1
// @grant none
// @run-at document-start
// @match https://steamcommunity.com/linkfilter/*
// ==/UserScript==
(() => {
'use strict';
let searchParams = new URLSearchParams(window.location.search);
let url = searchParams.get('url');
if (url) {
window.location.replace(url);
}
})();

View File

@ -0,0 +1,17 @@
// ==UserScript==
// @name twitter ?s=20 remover
// @version 1
// @grant none
// @match https://twitter.com/*
// @run-at document-start
// ==/UserScript==
(() => {
'use strict';
let searchParams = new URLSearchParams(window.location.search);
let strangeValue = searchParams.get('s');
if (/[0-9]+/.test(strangeValue)) {
searchParams.delete('s');
window.location.search = searchParams.toString();
}
})();

View File

@ -0,0 +1,30 @@
// ==UserScript==
// @name YouTube screenshotter
// @version 1
// @grant none
// @match https://www.youtube.com/*
// @run-at document-end
// ==/UserScript==
(() => {
'use strict';
function main() {
window.__userscript__takeScreenshot = function (video, imageType = 'image/png') {
if (!(video instanceof HTMLVideoElement)) {
throw new Error('Assertion failed: video instanceof HTMLVideoElement');
}
let canvas = document.createElement('canvas');
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
let ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, video.videoWidth, video.videoHeight);
window.open(canvas.toDataURL(imageType), '_blank');
};
}
let script = document.createElement('script');
script.append('(' + main + ')();');
(document.body || document.head || document.documentElement).appendChild(script);
})();