From f62f9bc0bab6b8e1d036ca384ad82c6ee8946b4b Mon Sep 17 00:00:00 2001 From: Dmytro Meleshko Date: Sat, 8 May 2021 22:00:21 +0300 Subject: [PATCH] Revert "[userscripts] use the available helper functions" This reverts commit 92361f9a54ee77a02f8826f0c2ea125f1f5be18e. --- .../github-icon-vertical-align.user.js | 29 ++++++++++++----- web/userscripts/github-line-height.user.js | 31 ++++++++++++++----- web/userscripts/github-tab-size.user.js | 31 ++++++++++++++----- web/userscripts/youtube-screenshot.user.js | 10 +++--- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/web/userscripts/github-icon-vertical-align.user.js b/web/userscripts/github-icon-vertical-align.user.js index eb24152..c30a35d 100644 --- a/web/userscripts/github-icon-vertical-align.user.js +++ b/web/userscripts/github-icon-vertical-align.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name GitHub icon vertical alignment fix -// @version 2 -// @grant GM_addStyle +// @version 3 +// @grant none // @match https://github.com/* // @match https://gist.github.com/* // @run-at document-start @@ -9,9 +9,24 @@ (() => { 'use strict'; - GM_addStyle(` - .btn-sm .octicon { - vertical-align: middle; - } - `); + + 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(); + }); + } })(); diff --git a/web/userscripts/github-line-height.user.js b/web/userscripts/github-line-height.user.js index 70b1aca..32aca81 100644 --- a/web/userscripts/github-line-height.user.js +++ b/web/userscripts/github-line-height.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name GitHub line-height -// @version 2 -// @grant GM_addStyle +// @version 3 +// @grant none // @match https://github.com/* // @match https://gist.github.com/* // @run-at document-start @@ -9,11 +9,26 @@ (() => { 'use strict'; + const LINE_HEIGHT = '1.2'; - GM_addStyle(` - .blob-num, .blob-code, .markdown-body .highlight pre, .markdown-body pre, - .cm-s-github-light .CodeMirror-lines, textarea.file-editor-textarea { - line-height: ${LINE_HEIGHT}; - } - `); + + 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(); + }); + } })(); diff --git a/web/userscripts/github-tab-size.user.js b/web/userscripts/github-tab-size.user.js index 1dd581b..570f79d 100644 --- a/web/userscripts/github-tab-size.user.js +++ b/web/userscripts/github-tab-size.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name GitHub tab size 4 -// @version 2 -// @grant GM_addStyle +// @version 3 +// @grant none // @match https://github.com/* // @match https://gist.github.com/* // @run-at document-start @@ -9,11 +9,26 @@ (() => { 'use strict'; + const TAB_SIZE = '4'; - GM_addStyle(` - * { - -moz-tab-size: ${TAB_SIZE} !important; - tab-size: ${TAB_SIZE} !important; - } - `); + + 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(); + }); + } })(); diff --git a/web/userscripts/youtube-screenshot.user.js b/web/userscripts/youtube-screenshot.user.js index e2c2f29..e4e0bac 100644 --- a/web/userscripts/youtube-screenshot.user.js +++ b/web/userscripts/youtube-screenshot.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name YouTube screenshotter -// @version 2 -// @grant GM_addElement +// @version 3 +// @grant none // @match https://www.youtube.com/* // @run-at document-end // ==/UserScript== @@ -24,7 +24,7 @@ }; } - GM_addElement('script', { - textContent: `(${main.toString()})();`, - }); + let script = document.createElement('script'); + script.append(`(${main.toString()})();`); + (document.body || document.head || document.documentElement).appendChild(script); })();