-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgithub-custom-options.user.js
129 lines (103 loc) · 4.6 KB
/
github-custom-options.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// ==UserScript==
// @name Github Custom Options
// @namespace http://stackoverflow.com/users/982924/rasg
// @author RASG
// @description Add options to github.com to (1) expand code box, (2) resize code font size, (3) expand answer box
// @require http://code.jquery.com/jquery.min.js
// @require https://raw.github.com/odyniec/MonkeyConfig/master/monkeyconfig.js
// @require https://cdn.jsdelivr.net/npm/siiimple-toast/dist/siiimple-toast.min.js
// @resource toastcss https://cdn.jsdelivr.net/npm/siiimple-toast/dist/style.css
// @include http*://github.com/*
// @icon https://www.google.com/s2/favicons?domain=github.com
// @version 2020.06.23.2018
// @grant GM_addStyle
// @grant GM_getMetadata
// @grant GM_getResourceText
// @grant GM_getValue
// @grant GM_notification
// @grant GM_registerMenuCommand
// @grant GM_setValue
// @grant GM_xmlhttpRequest
// @run-at document-start
// @noframes
// ==/UserScript==
// -----------------------------------------------------------------------------
// LOAD TOAST NOTIFICATIONS LIBRARY
// -----------------------------------------------------------------------------
// @require https://cdn.jsdelivr.net/npm/siiimple-toast/dist/siiimple-toast.min.js
// @resource toastcss https://cdn.jsdelivr.net/npm/siiimple-toast/dist/style.css
// @grant GM_addStyle
// @grant GM_getResourceText
GM_addStyle( GM_getResourceText("toastcss") );
var toast = siiimpleToast.setOptions({
position: 'top|right',
duration: 4000,
});
// -----------------------------------------------------------------------------
// PREVENT JQUERY CONFLICT
// -----------------------------------------------------------------------------
var $ = window.$;
var jQuery = window.jQuery;
this.$ = this.jQuery = jQuery.noConflict(true);
if (typeof $ == 'undefined') console.log('JQuery not found; The script will certainly fail');
// -----------------------------------------------------------------------------
// OPTIONS / CONFIG MENU
// -----------------------------------------------------------------------------
var parametros = {
code_font_resize : { type: 'checkbox', default: false },
code_font_size : { type: 'number', default: 12 },
page_wide : { type: 'checkbox', default: true },
};
var cfg;
try {
cfg = new MonkeyConfig({
title: 'Config Github Options',
menuCommand: true,
onSave: function() { fnSaveChanges(); },
params: parametros
});
console.log("MonkeyConfig loaded; The settings menu will be enabled");
}
catch(err) {
console.log(err);
console.log("MonkeyConfig not loaded; The settings menu will be disabled");
cfg = {
params: parametros,
get: function get(name) { return GM_getValue(name, this.params[name].default) }
}
}
// -----------------------------------------------------------------------------
// START
// -----------------------------------------------------------------------------
var shouldreload = false;
// apply imediately at document start
fnCheckChanges();
// also wait for page load. jquery will be ready here
$(function() {
// monitor the page for changes and reapply if necessary
// use 'observer.disconnect()' in 'fnCheckChanges()' to stop monitoring
var alvo = document.querySelector('body');
var observer = new MutationObserver(fnCheckChanges);
observer.observe(alvo, { attributes: false, characterData: false, childList: true, subtree: true });
});
// -----------------------------------------------------------------------------
// FUNCTIONS
// -----------------------------------------------------------------------------
function fnCheckChanges(changes, observer) {
var code_font_size = '';
if (cfg.get("code_font_resize")) code_font_size = cfg.get("code_font_size") + 'px';
$('td.blob-code-inner, td.blob-num').css({'font-size':code_font_size});
var page_size = '';
if (cfg.get("page_wide")) page_size = 'unset';
$('div.container-lg, div.container-xl').css({'max-width':page_size});
}
// -----------------------------------------------------------------------------
function fnSaveChanges() {
$('body').on("click", "#reloadnow", function() {
$(this).fadeOut("fast", function() { document.location.reload(false); });
});
var msg_success = 'Settings saved';
toast.success(msg_success);
var msg_reload = '<span id="reloadnow"> Some changes will be applied after you reload the page. <br> Click here to reload now </span>';
if (shouldreload) toast.message(msg_reload, { delay: 3000, duration: 7000 });
}