-
Notifications
You must be signed in to change notification settings - Fork 1
/
userscript.user.js
385 lines (317 loc) · 11 KB
/
userscript.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
// ==UserScript==
// @name Decreased Productivity Plus
// @icon http://i.imgur.com/ffgP58A.png
// @namespace skoshy.com
// @version 0.9.15
// @description Makes webpages more discreet
// @author Stefan Koshy
// @updateURL https://github.com/skoshy/DecreasedProductivityPlus/raw/master/userscript.user.js
// @match *://*/*
// @match http*://*.messenger.com/*
// @match http*://*.slack.com/messages/*
// @match http*://mail.google.com/mail/*
// @match http*://hangouts.google.com/webchat/*
// @grant GM_getValue
// @grant GM_setValue
// ==/UserScript==
var DEBUG_MODE = false;
var SCRIPT_ID = 'dpplus';
var CURRENT_SITE = getCurrentSite();
// From https://gist.github.com/arantius/3123124
// These are replacement functions for GreaseMonkey scripts, but the only work on a single domain instead of being cross domain
// Todo: Implement solution that works cross domain
if (typeof GM_getValue == 'undefined') {
function GM_getValue(aKey, aDefault) {
'use strict';
let val = localStorage.getItem(SCRIPT_ID + aKey);
if (null === val && 'undefined' != typeof aDefault) return aDefault;
return val;
}
}
if (typeof GM_setValue == 'undefined') {
function GM_setValue(aKey, aVal) {
'use strict';
localStorage.setItem(SCRIPT_ID + aKey, aVal);
}
}
var css = {};
css.defaults = {};
css.defaults.imageOpacity = '.05';
css.defaults.imageOpacityHover = '.4';
css.defaults.imageOpacitySmall = '.2';
css.defaults.imageOpacitySmallHover = '.55';
css.overrides = {};
css.overrides.disableUnfocusedTransparency = [
'gmailhangouts'
];
css.common = {};
css.common.css = `
html {
transition: opacity .1s ease-in-out;
}
html.unfocused {
opacity: .1;
}
html, body, div, p, span, a, table, td {
font-family: Arial, sans-serif !important;
font-size: 13px !important;
font-weight: 400 !important;
color: #222 !important;
background-color: rgba(255, 255, 255, .3) !important;
}
img, figure, video
{opacity: {{imageOpacity}};}
img:hover, figure:hover, video:hover
{opacity: {{imageOpacityHover}};}
`;
css.messenger = {};
css.messenger.css = `
._1z8r img {font-size: 30px !important; opacity: .2;} /* Reaction images (emoji) in the react popup */
._55lt img, /* Left hand avatars */
._4ld- div[style]:not([class]), /* Left hand avatars (group icons) */
._3xn1, /* Link Thumbnails */
._4tsk, /* Photo Messages */
.img, /* Other images */
[role="img"], /* more images */
._2pon /* Little blue messenger overlays */
{opacity: {{imageOpacity}};}
._2560, /* Small Emoji */
._1ifu /* Medium Emoji (32x32) */
{ opacity: .2; }
._55lt img:hover,
._4ld- div[style]:not([class]):hover,
._3xn1:hover,
._4tsk:hover,
.img:hover,
[role="img"]:hover,
._2pon:hover
{opacity: {{imageOpacityHover}};}
._1a-, /* small fb emojis */
.emoticon, /* embedded-in-messages emoji */
._5qi2 /* medium fb emojis standalone */
{opacity: {{imageOpacitySmall}};}
._1a-:hover,
.emoticon:hover,
._5qi2:hover,
{opacity: {{imageOpacitySmallHover}};}
/* Unread Messages override */
._1ht3 * { font-weight: bold !important; }
._52mr /* Get rid of messages background */
{ background-color: transparent !important; }
._hw2 ._53ij /* "Delete" Message Background Fix */
,.uiTooltipX .tooltipContent /* Various Tooltips */
{background-color: rgba(0,0,0,.1) !important;}
`;
css.slack = {};
css.slack.css = `
#col_channels_bg, #col_channels, #team_menu, #quick_switcher_btn, #team_menu_overlay, #col_channels_overlay {
background: #f9f9f9 !important;
} /* sidebar background */
#quick_switcher_btn #quick_switcher_label, #quick_switcher_btn .ts_icon, #quick_switcher_btn #quick_switcher_shortcut, body #team_menu_user_name {
color: #222 !important;
}
#team_header_user_name, /* username in sidebar */
body .channels_list_holder ul li .primary_action.im_name > *:not(.unread_highlights) /* Items in sidebar */
{color: black !important;}
body #channels_scroller.show_which_channel_is_active ul li.active .primary_action.im_name > *:not(.unread_highlights) /* Selected item in sidebar */
{color: black !important;}
#col_channels h2 {
color: black !important;
} /* section headers in sidebar */
#channels_scroller.show_which_channel_is_active ul li.active a.channel_name, #channels_scroller.show_which_channel_is_active ul li.active a.group_name, #channels_scroller.show_which_channel_is_active ul li.active a.im_name, #channels_scroller.show_which_channel_is_active ul li.active a.mpim_name, #channels_nav ul li.unread_link.active a {
background: #eee;
} /* highlighted things in slack, like the current tab you're looking at */
body:not(.sorting_mode) .channels_list_holder ul li a:hover, #monkey_scroll_wrapper_for_channels_scroller .monkey_scroll_bar,
body:not(.loading) #team_menu:hover, body:not(.loading) #team_menu.active, #quick_switcher_btn:hover, #quick_switcher_btn:active {
background: #ddd;
} /* highlighted things, hovering over them */
#channel_scroll_up /* the MORE UNREADS thing that shows up in the chat list when there's unread messages */
{top: 10px;}
.ts_tip .ts_tip_multiline_inner, .ts_tip:not(.ts_tip_multiline) .ts_tip_tip /* tooltip, like when mousing over a message reaction */
{background: rgba(0,0,0,.65) !important; border: 1px solid gray; color: white !important;}
#msgs_div img, #msgs_div figure, /* most images */
#msgs_div .member_image /* avatars in message panel */
{opacity: {{imageOpacity}};}
#msgs_div img:hover, #msgs_div figure:hover,
#msgs_div .member_image:hover
{opacity: {{imageOpacityHover}};}
`;
css.gmail = {};
css.gmail.css = `
.wl /*Background color */
{ background: white !important; }
.zE /* Unread Email rows */,
.yO /* Read Email Rows */
{ background: transparent !important; }
.TI .T-I-ax7, .z0 .T-I-ax7, .G-atb .T-I-ax7 /* Buttons, like the settings button, refresh, labels button, etc */
{ background: #ddd !important; }
.ZY /* Header that shows up if you're forwarding any email to a new email address */
{background-color: rgba(255,221,221,.2);}
`;
css.gmailhangouts = {};
css.gmailhangouts.css = `
.TsiDff /* Whole chat box */
{opacity: .2; transition: opacity .1s ease-in-out;}
.TsiDff:hover /* Hover over chat box */
{opacity: 1;}
.Ik /* Chat header */
{background: rgba(0,0,0,.5) !important;}
.uB /* Chat header, new message */
{background: rgba(83, 169, 63,.6) !important; border-bottom-color: rgba(83, 169, 63,.6);}
.GN * /* Chat header text */
{color: white !important;}
div.EV, /* Chat top button bar */
.iN /* Chat background */
{background: rgba(255, 255, 255, .9) !important;}
.Ia .Bb /* Chat list contact */
{transition: background .1s ease-in-out;}
.Ia .Bb:hover, .Ia .Bb:focus /* Chat list contact, hovering */
{background: rgba(35,35,35,.1);}
.Ia .Bb>.R8jgRe>.ng /* Chat list, contact text */
{text-shadow: none;}
`;
css.inbox = {};
css.inbox.css = `
.ss, .qG, .qG * /* Bolded Messages */
{ font-weight: bold !important; }
`;
css.none = {};
css.none.css = ``;
function addGlobalStyle(css, className, enabled, id) {
var head, style;
head = document.getElementsByTagName('head')[0];
if (!head) { return; }
style = document.createElement('style');
style.type = 'text/css';
style.innerHTML = css;
style.id = id;
style.className = className;
head.appendChild(style);
style.disabled = !enabled;
}
function getCssStyleElements() {
return document.getElementsByClassName(SCRIPT_ID+'-css');
}
function getBgElements() {
return document.querySelectorAll('[style*="url("]');
}
function getGradientString() {
return 'linear-gradient(rgba(255, 255, 255, 0.7) 0%, rgba(255, 255, 255, 0.7) 100%), ';
}
function enableStyle() {
var cssToInclude = '';
var bgEls = getBgElements();
var gradientString = getGradientString();
addGlobalStyle(parseCSS(
css.common.css + css[CURRENT_SITE].css
), SCRIPT_ID+'-css', true, SCRIPT_ID+'-css');
// enable all background image manipulations
for (var i = 0; i < bgEls.length; i++) {
bgEls[i].attributes.origBackgroundImage = bgEls[i].style.backgroundImage;
bgEls[i].style.backgroundImage = gradientString + bgEls[i].style.backgroundImage;
}
}
function disableStyle() {
var cssEls = getCssStyleElements();
var bgEls = getBgElements();
for (let i = 0; i < cssEls.length; i++) {
cssEls[i].parentNode.removeChild(cssEls[i]); // remove the element
}
// disable all background image manipulations
for (var i = 0; i < bgEls.length; i++) {
bgEls[i].style.backgroundImage = bgEls[i].attributes.origBackgroundImage;
}
}
function isStyleEnabled() {
var cssEl = document.getElementById(SCRIPT_ID+'-css');
return isTruthy(cssEl);
}
function parseCSS(parsed) {
for (attribute in css.defaults) {
exceptionToReplace = new RegExp('{{'+attribute+'}}', 'g');
parsed = parsed.replace(exceptionToReplace, css['defaults'][attribute]);
}
return parsed;
}
document.addEventListener("keydown", function(e) {
if (e.altKey === true && e.shiftKey === false && e.ctrlKey === false && e.metaKey === false && e.code == 'KeyI') {
if (isStyleEnabled()) {
disableStyle();
if (CURRENT_SITE != 'none') {GM_setValue( 'enabled_'+CURRENT_SITE , false );}
} else {
enableStyle();
if (CURRENT_SITE != 'none') {GM_setValue( 'enabled_'+CURRENT_SITE , true );}
}
}
});
function getCurrentSite() {
var url = document.documentURI;
var toReturn = 'none';
if (url.indexOf('messenger.com') != -1) toReturn = 'messenger';
if (url.indexOf('slack.com') != -1) toReturn = 'slack';
if (url.indexOf('mail.google.com') != -1) toReturn = 'gmail';
if (url.indexOf('hangouts.google.com/webchat') != -1) toReturn = 'gmailhangouts';
if (url.indexOf('inbox.google.com') != -1) toReturn = 'inbox';
return toReturn;
}
function init() {
var styleEnabled = GM_getValue( 'enabled_'+CURRENT_SITE , true );
if (CURRENT_SITE == 'none') styleEnabled = false; // don't automatically enable if the site isn't specifically tailored for the script
if (styleEnabled) {
enableStyle();
}
// unfocus / focus transparency effect
if (css.overrides.disableUnfocusedTransparency.indexOf(CURRENT_SITE) == -1) {
addEvent(window, "mouseout", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (from == null) {
// the cursor has left the building
hideHtml();
} else {
showHtml();
}
});
addEvent(window, "mouseover", function(e) {
e = e ? e : window.event;
var from = e.relatedTarget || e.toElement;
if (from != null) {
showHtml();
}
});
}
}
function hideHtml() {
document.querySelector('html').classList.add('unfocused');
}
function showHtml() {
document.querySelector('html').classList.remove('unfocused');
}
init();
/*
* Utility functions
*/
function isTruthy(item) {
return !isFalsy(item);
}
// from https://gist.github.com/skoshy/69a7951b3070c2e2496d8257e16d7981
function isFalsy(item) {
if (
!item
|| (typeof item == "object" && (
Object.keys(item).length == 0 // for empty objects, like {}, []
&& !(typeof item.addEventListener == "function") // omit webpage elements
))
)
return true;
else
return false;
}
function addEvent(obj, evt, fn) {
if (obj.addEventListener) {
obj.addEventListener(evt, fn, false);
}
else if (obj.attachEvent) {
obj.attachEvent("on" + evt, fn);
}
}