-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtechcrunch.user.js
65 lines (54 loc) · 2.04 KB
/
techcrunch.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
// ==UserScript==
// @name TechCrunch - Stay Focussed
// @namespace http://saiprasad.me/
// @description Unfocusses clutter on TechCrunch and helps on focussing on content that matter
// @version 0.2
// @match http://techcrunch.com/*
// @match https://techcrunch.com/*
// ==/UserScript==
/*global window, document*/
(function () {
"use strict";
var CLASS_CONTENT = "__focussed_content",
CLASS_GARBAGE = "__focussed_unfocus",
ID_STYLE = "__focussed";
// main article container
var article = document.querySelector("div[role=main]");
if (article) {
article.classList.add(CLASS_CONTENT);
var node = article,
parent = node.parentNode;
while (node && parent && parent.children) {
var children = parent.children;
for (var i = 0, l = children.length; i < l; i++) {
var child = children.item(i);
if (child !== node) {
child.classList.add(CLASS_GARBAGE);
}
}
node = parent;
parent = parent.parentNode;
}
}
// Garbage inside the article
var garbage = document.querySelectorAll("footer, .feature-island-container, .l-sidebar, .social-cluster, .social-share, aside, .article-extra");
for (var i = 0, l = garbage.length; i < l; i++) {
var child = garbage.item(i);
child.classList.add(CLASS_GARBAGE);
}
// Add stylesheet..
var sheet = document.createElement("style");
sheet.type = "text/css";
sheet.id = ID_STYLE;
sheet.innerHTML = "@media screen {." + CLASS_GARBAGE + " {opacity: 0.25; }}";
(document.head || document.documentElement).appendChild(sheet);
// Listen for toggling keyboard shortcut (Shift + ~)
window.addEventListener("keypress", function (event) {
if (event.shiftKey && event.keyCode === 126) {
var style_node = document.getElementById(ID_STYLE);
if (style_node) {
style_node.disabled = !style_node.disabled;
}
}
}, false);
}());