-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvgnews.js
196 lines (176 loc) · 4.72 KB
/
vgnews.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
// Removers
const blockAdBlockAds = () => {
console.info('blockAdBlockAds');
$('button[data-stats-string="Adblock::OpenPopup"]').parent().remove();
$('div#ad-topboard').remove();
$('div.df-skin-cm-yellowbg').remove(); // Edge case
}
const removeTopBar = () => {
console.info('removeTopBar');
$('div#top-bar').remove();
}
const removeHeader = () => {
console.info('removeHeader');
$('header[role="banner"]').remove();
}
const removeFooterAndAllThatStuffDownThere = () => {
console.info('removeFooterAndAllThatStuffDownThere');
$('div#trafikkfondet-front').remove();
$('div.betting-widgets').remove();
$('div.vg-services').remove();
$('div#tv-guide').remove();
$('footer').remove();
}
const removeSideBar = () => {
console.info('removeSideBar');
$('aside.reg-grid-aside').remove();
}
const removeArticleImages = () => {
console.info('removeArticleImages');
$('div.article-extract').find('img').parent().parent().remove();
}
// yCombify
const DEBUG = false;
const yCombify = () => {
console.info('yCombify');
// Extract articles
let articles = [];
$('div.article-content').each(function() {
if (DEBUG) console.log('article', this);
// Extract text
let text = '';
$(this).find('h3 a').each(function() {
let snippet = $(this).text();
if (snippet) text += snippet + ' ';
});
text = text.trim();
if (DEBUG) console.log('text', text);
// Extract href
const href = $(this).find('a').attr('href');
if (DEBUG) console.log('href', href);
// Save it
if (text !== '') {
if (href.indexOf('.no/') !== -1) {
const domain = href.match(/([a-zA-Z0-9\.]+)\//)[1].replace('www.','');
articles.push('<li><a href="'+href+'">'+text+'</a> ('+domain+')</li>');
}
else {
articles.push('<li><a href="'+href+'">'+text+'</a></li>');
}
}
});
// Clear space for articles
$('body').css('background-color', 'white');
$('div.reg-grid-container')
.html('')
.css('background-color', 'rgb(246, 246, 239)')
.css('margin-top', '10px')
;
// List articles like on HN
const logo = chrome.extension.getURL("128.png");
$('div.reg-grid-container').html([
'<div id="hackerheader">',
'<img src="'+logo+'" /> ',
'<span id="title">VG News</span>',
'<span id="pages">new | comments | show | ask | jobs | submit</span>',
'<span id="login">login</span>',
'</div>',
'<ol id="hackerlist">'+articles.join(' ')+'</ol>',
'<br />',
'<div id="footer">"VG News" made by Michael Johansen ([email protected]) for demo purposes.</div>',
'<br />',
].join(''));
// Style the header
$('div#hackerheader')
.attr('style', 'font-size: 13px !important')
.css('font-weight', 'bold')
.css('background-color', '#da0a16')
.css('color', 'black')
.css('height', '24px')
;
$('div#hackerheader img')
.css('position', 'relative')
.css('width', '20px')
.css('height', 'auto')
.css('margin', '2px')
;
$('div#hackerheader span#title')
.css('position', 'relative')
.css('margin-left', '3px')
.css('line-height', '1')
.css('top', '-7px')
;
$('div#hackerheader span#pages')
.css('position', 'relative')
.css('font-weight', 'normal')
.css('top', '-7px')
.css('left', '7px')
;
$('div#hackerheader span#login')
.css('position', 'relative')
.css('float', 'right')
.css('font-weight', 'normal')
.css('top', '6px')
.css('right', '7px')
;
// Style the list
$('ol#hackerlist')
.attr('style', 'font-size: 10pt !important')
.css('font-family', 'verdana')
.css('font-style', 'normal')
.css('font-weight', 'normal')
.css('list-style-type', 'decimal')
.css('margin-left', '35px')
.css('padding-top', '8px')
;
$('ol#hackerlist li')
.css('color', 'gray')
;
$('ol#hackerlist li a')
.css('color', 'black')
.css('line-height', '2')
;
// Style the footer
$('div#footer')
.css('margin', '10px')
.css('font-weight', 'bold')
;
}
// Run all
const runAll = () => {
if (document.location.href === 'https://www.vg.no/') {
// Remove basic stuff
blockAdBlockAds();
removeTopBar();
removeHeader();
removeSideBar();
removeFooterAndAllThatStuffDownThere();
// Remove article images
removeArticleImages();
// Ycombify
yCombify();
}
else if (document.location.href.startsWith('https://www.vg.no/')) {
// Remove basic stuff
blockAdBlockAds();
removeTopBar();
removeHeader();
removeSideBar();
// removeFooterAndAllThatStuffDownThere(); // Makes the white BG cut off too early
}
}
$(document).ready(() => setTimeout(runAll, 2000));
// Key controls
// $(document).keydown(function(evt) {
// if (!window.triggered) {
// switch (evt.key) {
// case 'y': {
// runAll();
// // Don't do it again
// window.triggered = true;
// break;
// }
// default: console.info('noop @', evt.key, '\ntry using R to remove stuff or Y to yCombify');
// }
// }
// });