-
Notifications
You must be signed in to change notification settings - Fork 0
/
scratchpad.js
113 lines (99 loc) · 3.89 KB
/
scratchpad.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
// ==UserScript==
// @name No distraction on Facebook, Messenger, YouTube, Quora and Google
// @namespace https://zachsaucier.com/
// @author Zach Saucier
// @match *://*/*
// @version 1
// @description Remove flashing title, notification count and other distracting elements when using them for work
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Set our list of sites and elements to block
var blockList = [
"www.youtube.com###watch7-sidebar-contents",
"www.youtube.com##.yt-masthead-logo-container",
"www.facebook.com##._1uh-:nth-of-type(2)",
"www.facebook.com##._2t-e > ._4kny:nth-of-type(1)",
"www.facebook.com##._1uh-:nth-of-type(1)",
"www.facebook.com##._50tj._2t-a",
"www.facebook.com##._50ti._2s1y._5rmj._26aw._2t-a",
"www.facebook.com###u_0_0",
"www.facebook.com###fbDockChatBuddylistNub > .fbNubButton"
"www.google.com/logos/doodles/$image"
"www.google.com##.gb_T.gb_eg.gb_R.gb_fg.gb_ib"
"www.quora.com##[id *= "_header"]"
"www.quora.com##[id $= "_header"]"
"www.quora.com##[id $= "_expanded"]"
];
// Get the window's hostname
var windowHostname = window.location.hostname;
// Iterate through the blocklist, hiding elements as needed
for(var i = 0; i < blockList.length; i++) {
var entryParts = blockList[i].split('##');
// Compare the hostnames; Only remove elements if they match
if(windowHostname === entryParts[0]) {
// Find the elements if they exists
var matchedElements = document.querySelectorAll(entryParts[1]);
// Actually remove the element(s) that match
for(var j = 0; j < matchedElements.length; j++) {
var matchedElem = matchedElements[j];
matchedElem.parentNode.removeChild(matchedElem);
}
}
}
})();
//Remove flashing title
function titleModified() {
var text = document.getElementsByTagName('title')[0].text;
if (text != 'Messenger') {
document.getElementsByTagName('title')[0].text = 'Messenger';
}
}
window.onload = function() {
var titleEl = document.getElementsByTagName("title")[0];
var docEl = document.documentElement;
if (docEl && docEl.addEventListener) {
docEl.addEventListener("DOMSubtreeModified", function(evt) {
var t = evt.target;
if (t === titleEl || (t.parentNode && t.parentNode === titleEl)) {
titleModified();
}
}, false);
} else {
document.onpropertychange = function() {
if (window.event.propertyName == "title") {
titleModified();
}
};
}
};
// Remove the notification in the page title
function removeTitleNotification() {
if(document.head.querySelector("title").innerText.indexOf(')') != -1)
document.head.querySelector("title").innerText = document.head.querySelector("title").innerText.split(')')[1];
}
removeTitleNotification();
var observeDOM = (function() {
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver,
eventListenerSupported = window.addEventListener;
return function(obj, callback) {
if(MutationObserver) {
// Define a new observer
var obs = new MutationObserver(function(mutations, observer){
if(mutations[0].addedNodes.length || mutations[0].removedNodes.length )
callback();
});
// Have the observer observe foo for changes in children
obs.observe(obj, {childList: true, subtree: true});
}
else if(eventListenerSupported ) {
obj.addEventListener('DOMNodeInserted', callback, false);
obj.addEventListener('DOMNodeRemoved', callback, false);
}
};
})();
// Observe a specific DOM element:
observeDOM(document.head.querySelector("title"), function() {
removeTitleNotification();
});