· 6 years ago · Feb 17, 2020, 12:50 PM
1// ==UserScript==
2// @name 眼不见心不烦(新浪微博)
3// @namespace http://weibo.com/salviati
4// @license MIT License
5// @description 新浪微博(weibo.com)非官方功能增强脚本,具有屏蔽关键词、用户、来源、链接,改造版面等功能
6// @features 修正直接查看大图功能失效的问题;修正紧凑版式下部分内容显示错位的问题
7// @version 2.6.1
8// @revision 111
9// @author @富平侯
10// @committers @牛肉火箭, @JoyerHuang_悦, @tsh90
11// @grant GM_getValue
12// @grant GM_setValue
13// @include http://weibo.com/*
14// @include http://www.weibo.com/*
15// @include http://d.weibo.com/*
16// @include https://weibo.com/*
17// @include https://www.weibo.com/*
18// @include https://d.weibo.com/*
19// @updateURL https://bitbucket.org/salviati/weibo-cleaner/downloads/weiboCleaner-latest.user.js
20// @downloadURL https://bitbucket.org/salviati/weibo-cleaner/downloads/weiboCleaner-latest.user.js
21// ==/UserScript==
22
23// 借助自定义事件实现page script(注入页面的主程序)与content script(运行在沙箱中)
24// 之间的异步通讯,使前者可以间接调用chrome.* API和GM_* API
25document.addEventListener('wbpGet', function (event) {
26 event.stopPropagation();
27 var name = event.detail.name;
28 var post = function (value) {
29 // 注意:不能在此处直接调用callback,否则回调函数将在本程序所在的沙箱环境中运行,在Chrome 27及更高版本下会出错
30 // 在Greasemonkey(Firefox扩展)环境下也不能通过detail直接传对象,只能送string或array
31 // 详见https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent#Specification
32 document.dispatchEvent(new CustomEvent('wbpPost', { detail: event.detail.id + '=' + (value || '') }));
33 };
34 post(GM_getValue(name, event.detail.defVal));
35});
36document.addEventListener('wbpSet', function (event) {
37 event.stopPropagation();
38 var data = {}, name = event.detail.name, value = event.detail.value;
39 data[name] = value;
40 GM_setValue(name, value);
41});
42// 将脚本注入页面环境
43(function (source) {
44 var script = document.createElement('script');
45 script.setAttribute('type', 'text/javascript');
46 script.textContent = '(' + source + ')();';
47 document.head.appendChild(script);
48 document.head.removeChild(script);
49})(function () {
50// 工具函数
51var $ = (function () {
52 // 按id选择元素(默认操作)
53 var $ = function (id) {
54 return document.getElementById(id);
55 };
56 $.version = Number('111');
57 // 按CSS选择元素
58 $.select = function (css) {
59 return document.querySelector(css);
60 };
61 var CHROME_KEY_ROOT = 'weiboPlus.';
62 if (window.chrome) {
63 if (localStorage.getItem(CHROME_KEY_ROOT + 'chromeExtInstalled')) {
64 console.warn('已安装插件版本,脚本停止运行!');
65 return undefined; // 如果已经(曾经)安装过插件则不再继续运行脚本
66 }
67 }
68 $.window = window;
69 $.config = $.window.$CONFIG;
70 if (!$.config) {
71 return undefined;
72 }
73 $.uid = $.config.uid;
74 if (!$.uid) {
75 return undefined;
76 }
77 $.oid = $.config.oid; // 页面uid(个人主页或单条微博的uid)
78 var callbacks = {};
79 document.addEventListener('wbpPost', function (event) {
80 event.stopPropagation();
81 var pos = event.detail.indexOf('=');
82 var id = event.detail.slice(0, pos), value = event.detail.slice(pos+1);
83 callbacks[id](value);
84 delete callbacks[id];
85 });
86 $.get = function (name, defVal, callback, sync) {
87 var messageID = Math.random().toString(36).slice(2); // 生成随机ID
88 callbacks[messageID] = callback;
89 document.dispatchEvent(new CustomEvent('wbpGet', { detail: {
90 name : name,
91 defVal : defVal,
92 id : messageID,
93 sync : sync
94 }}));
95 };
96 $.set = function (name, value, sync) {
97 document.dispatchEvent(new CustomEvent('wbpSet', { detail: {
98 name : name,
99 value : value,
100 sync : sync
101 }}));
102 };
103 // 删除节点
104 $.remove = function (el) {
105 if (el) { el.parentNode.removeChild(el); }
106 };
107 // 绑定click事件
108 $.click = function (el, handler) {
109 if (el) { el.addEventListener('click', handler, false); }
110 };
111 // 返回当前页面的位置
112 $.scope = function () {
113 return document.body.classList.contains('FRAME_main') ? 1 : document.body.classList.contains('FRAME_page') ? (document.domain === 'd.weibo.com' ? 3 : 2) : 0;
114 };
115 return $;
116})();
117
118if (!$) { return false; }
119
120function Options () {
121 // 各类型默认值
122 var typeDefault = {
123 keyword : [],
124 string : '',
125 bool : false,
126 radio : '',
127 array : [],
128 object : {},
129 internal : null
130 };
131 for (var option in this.items) {
132 if (this.items[option].length > 1) {
133 // 使用属性默认值
134 this[option] = this.items[option][1];
135 } else {
136 // 使用类型默认值
137 this[option] = typeDefault[this.items[option][0]];
138 }
139 }
140}
141
142Options.prototype = {
143 // 选项类型与默认值
144 items : {
145 version : ['internal', 0], // 内部变量:不在设置界面出现,不随设置导出
146 whiteKeywords : ['keyword'],
147 blackKeywords : ['keyword'],
148 grayKeywords : ['keyword'],
149 sourceKeywords : ['keyword'],
150 sourceGrayKeywords : ['keyword'],
151 userBlacklist : ['array'],
152 tipBackColor : ['string', '#FFD0D0'],
153 tipTextColor : ['string', '#FF8080'],
154 readerModeIndex : ['bool'],
155 readerModeProfile : ['bool'],
156 readerModeTip : ['internal', false], // 内部变量:不在设置界面出现,不随设置导出
157 readerModeWidth : ['string', 750],
158 smallImgLayout : ['bool'],
159 customImgSize : ['string', 80],
160 customTotalWidth : ['string', 250],
161 customVideoSize : ['string', 120],
162 squareAvatar : ['bool'],
163 moveSrcToBtm : ['bool'],
164 unwrapText : ['bool'],
165 compactFeedToolbar : ['bool'],
166 noHomeRightBar : ['bool'],
167 noHomeMargins : ['bool'],
168 noHotYellowTags : ['bool'],
169 directBigImg : ['bool'],
170 directAllFeeds : ['bool'],
171 showAllArticleText : ['bool'],
172 showAllText : ['bool'],
173 showAllGroups : ['bool'],
174 showAllMsgNav : ['bool'],
175 showAllSonFeeds : ['bool'],
176 noDefaultGroupPub : ['bool'],
177 clearDefTopic : ['bool'],
178 overrideMyBack : ['bool'],
179 overrideOtherBack : ['bool'],
180 backColor : ['string', 'rgba(100%,100%,100%,0.2)'],
181 overrideMySkin : ['bool'],
182 overrideOtherSkin : ['bool'],
183 skinID : ['string', 'skinvip001'],
184 filterOthersOnly : ['bool'],
185 filterPaused : ['bool'],
186 filterSmiley : ['bool'],
187 filterName : ['bool', true],
188 filterPromotions : ['bool'],
189 filterHot : ['bool'],
190 filterLiked : ['bool'],
191 filterTopic : ['bool'],
192 filterDeleted : ['bool'],
193 filterTaobao : ['bool'],
194 filterFlood : ['bool'],
195 maxFlood : ['string', 5],
196 updateNotify : ['bool', true],
197 useCustomStyles : ['bool', true],
198 customStyles : ['string'],
199 hideMods : ['array']
200 },
201 // 去除内部变量并转换为字符串
202 strip : function () {
203 var stripped = {};
204 for (var option in this.items) {
205 if (this.items[option][0] !== 'internal') {
206 stripped[option] = this[option];
207 }
208 }
209 return JSON.stringify(stripped);
210 },
211 // 保存设置
212 save : function (noSync) {
213 this.version = $.version;
214 $.set($.uid.toString(), JSON.stringify(this));
215 },
216 // 载入/导入设置,输入的str为undefined(首次使用时)或string(非首次使用和导入设置时)
217 load : function (str) {
218 var parsed = {};
219 if (str) {
220 try {
221 parsed = JSON.parse(str.replace(/\n/g, ''));
222 if (typeof parsed !== 'object') { throw 0; }
223 } catch (e) {
224 parsed = {};
225 str = null; // 出错,最后返回false
226 }
227 }
228 // 填充选项
229 for (var option in this.items) {
230 if (option in parsed) {
231 this[option] = parsed[option];
232 }
233 }
234 // == LEGACY CODE START ==
235 // 自动转换“大家正在热搜”选项
236 if (parsed.clearHotSearch) {
237 this.hideMods.push("HotSearch");
238 }
239 // 采用“紧凑型工具栏”或“微博作者后不折行”时自动将微博来源置于底部
240 if (parsed.unwrapText || parsed.compactFeedToolbar) {
241 this.moveSrcToBtm = true;
242 }
243 // == LEGACY CODE END
244 return (str !== null);
245 }
246};
247
248var $options = new Options();
249
250var $dialog = (function () {
251 var shown = false, dialog, content, STK;
252 var getDom = function (node) {
253 // 首页与主页API不一致
254 return content ? content.getDom(node) : dialog.getDomList()[node];
255 };
256 var bind = function (node, func, event) {
257 STK.core.evt.addEvent(getDom(node), event || 'click', func);
258 };
259 // 从显示列表建立关键词数组
260 var getKeywords = function (id, attr) {
261 return Array.prototype.map.call(getDom(id).childNodes, function (keyword) {
262 return attr ? keyword.getAttribute(attr) : keyword.textContent;
263 });
264 };
265 // 将关键词添加到显示列表
266 var addKeywords = function (id, list, attr) {
267 var keywords;
268 if (list instanceof Array) {
269 keywords = list;
270 } else {
271 keywords = [];
272 var str = ' ' + getDom(list).value + ' ', regex = new RegExp('(\\s"([^"]+)"\\s|\\s([^\\s]+)\\s)', 'g'), result;
273 while ((result = regex.exec(str)) !== null) {
274 keywords.push(result[2] || result[3]); // 提取关键词
275 --regex.lastIndex;
276 }
277 }
278 var illegalRegex = keywords.filter(function (keyword) {
279 if (!keyword || getKeywords(id, attr).indexOf(keyword) !== -1) { return false; }
280 var keywordLink = document.createElement('a');
281 // 关键词是正则表达式?
282 if (keyword.length > 2 && keyword.charAt(0) === '/' && keyword.charAt(keyword.length - 1) === '/') {
283 try {
284 // 尝试创建正则表达式,检验正则表达式的有效性
285 // 调用test()是必须的,否则浏览器可能跳过该语句
286 RegExp(keyword.slice(1, -1)).test('');
287 } catch (e) {
288 return true;
289 }
290 keywordLink.className = 'regex';
291 }
292 keywordLink.title = '点击删除';
293 keywordLink.setAttribute('action-type', 'remove');
294 if (attr) { keywordLink.setAttribute(attr, keyword); }
295 keywordLink.href = 'javascript:void(0)';
296 keywordLink.textContent = keyword;
297 getDom(id).appendChild(keywordLink);
298 return false;
299 });
300 if (!(list instanceof Array)) {
301 // 在文本框中显示无效的正则表达式并闪烁提示
302 getDom(list).value = illegalRegex.join(' ');
303 if (illegalRegex.length) {
304 // 首页与主页API不一致
305 (STK.common.extra ? STK.common.extra.shine : STK.kit.extra.shine)(getDom(list));
306 }
307 }
308 };
309 var usercardLoaded = false;
310 // 将用户添加到屏蔽用户列表
311 var addUsers = function (id, list) {
312 var updateOnly = !list, div = getDom(id);
313 // 整个列表只载入一次
314 if (updateOnly && usercardLoaded) { return; }
315 var users = updateOnly ? getKeywords(id, 'uid') : getDom(list).value.split(' '),
316 unprocessed = users.length, unfound = [];
317 users.forEach(function (user) {
318 var request = { type : 1 };
319 if (updateOnly) {
320 request.id = user;
321 } else {
322 request.name = user;
323 }
324 STK.jsonp({
325 url : '/aj/v6/user/newcard?ajwvr=6',
326 args : request,
327 method : 'get',
328 responseType : 'json',
329 varkey : 'callback',
330 timeout : 3e4,
331 onComplete : function (result) {
332 var link;
333 if (updateOnly) {
334 link = div.querySelector('a[uid="' + request.id + '"]');
335 } else {
336 link = document.createElement('a');
337 }
338 if (result.code === '100000') { // 成功
339 var img = result.data.match(/<img[^>]+>/)[0];
340 if (!updateOnly) { request.id = img.match(/uid="([^"]+)"/)[1]; }
341 // 防止重复添加
342 if (updateOnly || getKeywords(id, 'uid').indexOf(request.id) === -1) {
343 link.innerHTML = '<img width="50" height="50" ' + img.match(/src="[^"]+"/)[0] + ' /><br />' + img.match(/title="([^"]+)"/)[1];
344 if (!updateOnly) {
345 // 添加新的用户
346 link.title = '点击删除';
347 link.href = 'javascript:void(0)';
348 link.setAttribute('uid', request.id);
349 link.setAttribute('action-type', 'remove');
350 div.appendChild(link);
351 }
352 }
353 } else if (updateOnly) {
354 link.innerHTML += '<br />(未找到)';
355 } else {
356 unfound.push(request.name);
357 }
358 if (--unprocessed === 0) {
359 // 全部处理完成,在文本框中显示未被添加的用户并闪烁提示
360 getDom(list).value = unfound.join(' ');
361 if (unfound.length) {
362 // 首页与主页API不一致
363 (STK.common.extra ? STK.common.extra.shine : STK.kit.extra.shine)(getDom(list));
364 }
365 }
366 },
367 onTraning : STK.funcEmpty,
368 onFail : STK.funcEmpty,
369 isEncode : true
370 });
371 });
372 usercardLoaded = true;
373 };
374 // 返回当前设置(可能未保存)
375 var exportSettings = function () {
376 var options = new Options(), radio;
377 for (var option in options.items) {
378 switch (options.items[option][0]) {
379 case 'keyword':
380 options[option] = getKeywords(option + 'List');
381 break;
382 case 'string':
383 options[option] = getDom(option).value;
384 break;
385 case 'bool':
386 options[option] = getDom(option).checked;
387 break;
388 case 'radio':
389 radio = getDom('tabs').querySelector('input[type="radio"][name="' + option + '"]:checked');
390 options[option] = radio ? radio.value : '';
391 break;
392 case 'array':
393 options[option] = [];
394 break;
395 case 'object':
396 options[option] = {};
397 break;
398 case 'internal':
399 // 内部变量保持不变
400 // WARNING: 内部变量如果是数组或对象,以下的浅拷贝方式可能导致设置的意外改变
401 options[option] = $options[option];
402 break;
403 }
404 }
405 options.userBlacklist = getKeywords('userBlacklist', 'uid');
406 for (var module in $page.modules) {
407 if (getDom('hide' + module).checked) {
408 options.hideMods.push(module);
409 }
410 }
411 getDom('settingsString').value = options.strip();
412 return options;
413 };
414 // 更新设置窗口内容,exportSettings()的反过程
415 var importSettings = function (options) {
416 var radio;
417 for (var option in options.items) {
418 switch (options.items[option][0]) {
419 case 'keyword':
420 getDom(option).value = '';
421 getDom(option + 'List').innerHTML = '';
422 addKeywords(option + 'List', options[option]);
423 break;
424 case 'string':
425 getDom(option).value = options[option];
426 break;
427 case 'bool':
428 getDom(option).checked = options[option];
429 break;
430 case 'radio':
431 radio = getDom('tabs').querySelector('input[type="radio"][name="' + option + '"][value="' + options[option] + '"]');
432 if (radio) { radio.checked = true; }
433 break;
434 }
435 }
436 getDom('userBlacklistNew').value = '';
437 getDom('userBlacklist').innerHTML = '';
438 addKeywords('userBlacklist', options.userBlacklist, 'uid');
439 usercardLoaded = false;
440 var tipBackColor = getDom('tipBackColor').value,
441 tipTextColor = getDom('tipTextColor').value,
442 tipSample = getDom('tipSample');
443 tipSample.style.backgroundColor = tipBackColor;
444 tipSample.style.borderColor = tipTextColor;
445 tipSample.style.color = tipTextColor;
446 for (var module in $page.modules) {
447 getDom('hide' + module).checked = (options.hideMods.indexOf(module) !== -1);
448 }
449 getDom('settingsString').value = options.strip();
450 };
451 // 创建设置窗口
452 var createDialog = function () {
453 // 由于操作是异步进行的,脚本载入时STK可能尚未载入,尤其是在Firefox中
454 // 鉴于只有$dialog使用STK,将其设置为内部变量,仅在打开设置窗口时载入
455 STK = $.window.STK;
456 if (!STK) {
457 console.warn('页面尚未载入完成,无法打开设置页面!');
458 return false;
459 }
460 var HTML = '<div node-type="outer" class="detail wbpSettings" style="padding: 0 20px 20px"><div class="clearfix"><div style="float: left">新浪微博<span style="color: red">非官方</span>功能增强脚本。</div><div style="float: right; display: inline; position: relative"><a href="https://bitbucket.org/salviati/weibo-cleaner" target="_blank">插件主页</a><em class="W_vline"></em><a href="https://bitbucket.org/salviati/weibo-cleaner/wiki/FAQ" title="遇到问题请先阅读FAQ" target="_blank">常见问题</a><em class="W_vline"></em><a href="/salviati" title="欢迎私信、评论或@作者提出建议" target="_blank">联系作者</a></div></div><div class="clearfix"><div node-type="tabHeaders" class="wbpTabHeaders"><a tab="tabKeywords" href="javascript:void(0);" class="current">关键词</a><a node-type="tabHeaderUser" tab="tabUser" href="javascript:void(0);">用户</a><a tab="tabSource" href="javascript:void(0);">来源</a><a tab="tabAdvanced" href="javascript:void(0);">高级</a><a tab="tabModules" href="javascript:void(0);">模块</a><a tab="tabModify" href="javascript:void(0);">改造版面</a><a node-type="tabHeaderSettings" tab="tabSettings" href="javascript:void(0);">设置</a></div><div node-type="tabs" style="float: right; width: 440px"><div node-type="tabKeywords"><div class="clearfix"><div style="float: left"><input type="checkbox" node-type="filterSmiley"><label title="如果选中,[呵呵]等表情也可以作为关键词被屏蔽">允许表情关键词</label><input type="checkbox" node-type="filterName" style="margin-left: 10px"><label title="如果选中,@富平侯 等用户名也可以作为关键词被屏蔽">在用户名中搜索关键词</label></div><div style="float: right; display: inline; position: relative"><span class="link"><a href="javascript:void(0);" style="cursor: help">关键词设置帮助<span><ul><li>如果要添加的关键词中有空格,可将其置于一对<span style="color: blue">半角双引号</span>内,如<span style="color: green">"I love you"</span></li><li>使用<span style="color: blue">加号</span>分隔需要同时出现的关键词,如<span style="color: green">A+B+C</span>代表A、B、C三个词必须同时出现</li><li>使用<span style="color: blue">斜杠</span>设置正则表达式关键词,如<span style="color: green">/转发并@.{2,3}好友/</span></li></ul></span></a></span></div></div><div class="wbpKeywordBlock"><em>白名单</em>包含下列关键词的微博不会被屏蔽<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="whiteKeywords" class="input" placeholder="多个关键词用空格隔开;不区分大小写;区分简繁体"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="add" action-data="list=whiteKeywordsList&text=whiteKeywords"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=whiteKeywordsList"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper"><div node-type="whiteKeywordsList" class="wbpKeywordsList wbpWhiteKeywordsList"></div></div></div><div class="wbpKeywordBlock"><em>黑名单</em>包含下列关键词的微博将被屏蔽<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="blackKeywords" class="input" placeholder="多个关键词用空格隔开;不区分大小写;区分简繁体"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="add" action-data="list=blackKeywordsList&text=blackKeywords"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=blackKeywordsList"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper"><div node-type="blackKeywordsList" class="wbpKeywordsList wbpBlackKeywordsList"></div></div></div><div class="wbpKeywordBlock"><em>灰名单</em>包含下列关键词的微博将被屏蔽<span style="color: red">并提示</span><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="grayKeywords" class="input" placeholder="多个关键词用空格隔开;不区分大小写;区分简繁体"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="add" action-data="list=grayKeywordsList&text=grayKeywords"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=grayKeywordsList"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper"><div node-type="grayKeywordsList" class="wbpKeywordsList wbpGrayKeywordsList"></div></div><table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top: 0px"><tbody><tr><td style="width: 110px">屏蔽提示背景颜色:</td><td><div class="wbpInput"><input type="text" node-type="tipBackColor" class="input"></div></td><td style="width: 15px"></td><td style="width: 110px">屏蔽提示文字颜色:</td><td><div class="wbpInput"><input type="text" node-type="tipTextColor" class="input"></div></td></tr></tbody></table><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td style="width: 40px">示例:</td><td><div node-type="tipSample" class="wbpTip" style="margin-bottom: 10px">本条来自<a href="javascript:void(0);">@某人</a>的微博因包含关键词“<a href="javascript:void(0);">XXXX</a>”而被隐藏,点击显示</div></td></tr></tbody></table></div></div><div node-type="tabUser" style="display: none"><p>如果一条微博的发布者或转发原文的作者为下列用户之一,微博将被屏蔽。除了在此处添加屏蔽用户,您还可以将鼠标悬停在用户链接上,在弹出的信息气球上点击“屏蔽”。</p><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="userBlacklistNew" class="input" placeholder="多个用户名用空格隔开;不要加上前面的@;不区分大小写"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="addUser" action-data="list=userBlacklist&text=userBlacklistNew"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=userBlacklist"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper" style="max-height: 230px"><div node-type="userBlacklist" class="wbpUserList wbpBlackKeywordsList"></div></div></div><div node-type="tabSource" style="display: none"><p>如果一条微博的来源(包括转发原文的来源)名称中包含指定关键词,微博将被屏蔽。如将“时光机”设为关键词可屏蔽所有来自<a href="http://time.xuapp.com/" target="_blank">时光机</a>或<a href="http://weibo.pp.cc/time/" target="_blank">皮皮时光机</a>等应用的微博。</p><div class="wbpKeywordBlock"><em>黑名单</em>来源名称包含下列关键词的微博将被屏蔽<table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="sourceKeywords" class="input" placeholder="多个关键词用空格隔开;不区分大小写;区分简繁体"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="add" action-data="list=sourceKeywordsList&text=sourceKeywords"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=sourceKeywordsList"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper"><div node-type="sourceKeywordsList" class="wbpKeywordsList wbpBlackKeywordsList"></div></div></div><div class="wbpKeywordBlock"><em>灰名单</em>来源名称包含下列关键词的微博将被屏蔽<span style="color: red">并提示</span><table width="100%" border="0" cellspacing="0" cellpadding="0"><tbody><tr><td><div class="wbpInput"><input type="text" node-type="sourceGrayKeywords" class="input" placeholder="多个关键词用空格隔开;不区分大小写;区分简繁体"></div></td><td class="wbpToolBtns"><a href="javascript:void(0);" class="W_btn_b" action-type="add" action-data="list=sourceGrayKeywordsList&text=sourceGrayKeywords"><span>添加</span></a><a href="javascript:void(0);" class="W_btn_b" action-type="clear" action-data="list=sourceGrayKeywordsList"><span>清空</span></a></td></tr></tbody></table><div class="wbpListWrapper"><div node-type="sourceGrayKeywordsList" class="wbpKeywordsList wbpGrayKeywordsList"></div></div></div></div><div node-type="tabAdvanced" style="display: none"><p>注意:对于所有屏蔽微博的功能,白名单具有最高优先级;如果一条微博包含白名单中的关键词,则<span style="color: red">一定不会</span>被屏蔽。</p><p><input type="checkbox" node-type="filterOthersOnly"><label>不要屏蔽我自己发布的微博</label></p><p><input type="checkbox" node-type="filterPaused"><label><span style="color: red">暂停屏蔽</span>:选中时暂时停止屏蔽微博</label></p><p><input type="checkbox" node-type="filterPromotions"><label>屏蔽推广微博</label></p><p><input type="checkbox" node-type="filterHot"><label>屏蔽热门微博(粉丝头条)</label></p><p><input type="checkbox" node-type="filterLiked"><label>屏蔽好友赞过的微博</label></p><p><input type="checkbox" node-type="filterTopic"><label>屏蔽关注话题推荐的微博</label></p><p><input type="checkbox" node-type="filterDeleted"><label>屏蔽已删除微博的转发</label></p><p><input type="checkbox" node-type="filterTaobao"><label class="WB_text">屏蔽带有 <a class="W_btn_b W_btn_cardlink btn_22px"><span class="ico_spe"><i class="W_icon icon_cd_tb"></i></span><span class="W_autocut">淘宝商品</span></a> 或 <a class="W_btn_b W_btn_cardlink btn_22px"><span class="ico_spe"><i class="W_icon icon_cd_tmall"></i></span><span class="W_autocut">天猫商品</span></a> 的微博</label></p><div style="margin-top: 5px"><input type="checkbox" node-type="filterFlood"><label>反刷屏:来自同一用户的微博最多显示</label><div class="wbpInput wbpInlineInput"><input type="text" node-type="maxFlood" class="input"></div>条</div></div><div node-type="tabModules" class="wbpTabModules" style="display: none"><p>请选择要屏蔽的版面内容。</p><table width="100%" border="0" cellspacing="0" cellpadding="0" style="line-height: 24px; margin-top: 15px"><tbody><tr><td><input type="checkbox" node-type="hideAds"><label>版面广告及嵌入式广告</label></td><td><input type="checkbox" node-type="hideHotSearch"><label>大家正在热搜(搜索栏)</label></td></tr><tr><td><input type="checkbox" node-type="hideFooter"><label>页底链接模块</label></td><td><input type="checkbox" node-type="hideRecommendedTopic"><label>热点微话题(发布框右上)</label></td></tr><tr><td><input type="checkbox" node-type="hideIMNews"><label>右下角新闻快讯</label></td><td><input type="checkbox" node-type="hideCommentTip"><label>评论栏顶端横幅</label></td></tr><tr><td><input type="checkbox" node-type="hideMusicPlayer"><label>微音乐播放器(左下角)</label></td><td><input type="checkbox" node-type="hideMemberTip"><label>微博会员推广横幅(页底)</label></td></tr><tr class="wbpRowSpacing"><td><input type="checkbox" node-type="hideRecomFeed"><label>精彩微博推荐(首页时间线)</label></td><td><input type="checkbox" node-type="hideTimelineMods"><label>时间线嵌入模块(好友关注等)</label></td></tr><tr><td><input type="checkbox" node-type="hideTopicCard"><label>微博话题卡片</label></td><td><input type="checkbox" node-type="hideLocationCard"><label>微博位置卡片</label></td></tr><tr><td><input type="checkbox" node-type="hideAppCard"><label>微博应用卡片</label></td><td><input type="checkbox" node-type="hideMemberCover"><label>会员微博背景</label></td></tr><tr class="wbpRowSpacing"><td><input type="checkbox" node-type="hideFriends"><label>好友圈</label></td><td><input type="checkbox" node-type="hideToMe"><label>群微博</label></td></tr><tr><td><input type="checkbox" node-type="hideHotWeibo"><label>热门微博</label></td><td><input type="checkbox" node-type="hideHongbao"><label>让红包飞(右边栏)</label></td></tr><tr><td><input type="checkbox" node-type="hideStats"><label>关注/粉丝/微博数</label></td><td><input type="checkbox" node-type="hideLevel"><label>用户等级</label></td></tr><tr><td><input type="checkbox" node-type="hideTopic"><label>热门话题</label></td><td><input type="checkbox" node-type="hideAttFeed"><label>好友关注动态</label></td></tr><tr><td><input type="checkbox" node-type="hideMusicRecom"><label>亚洲新歌榜/好书榜</label></td><td><input type="checkbox" node-type="hideMovieRecom"><label>电影热议榜</label></td></tr><tr><td><input type="checkbox" node-type="hideMember"><label>会员专区</label></td><td><input type="checkbox" node-type="hideNotice"><label>公告栏</label></td></tr><tr class="wbpRowSpacing"><td><input type="checkbox" node-type="hideVerifyIcon"><label>个人/机构认证标识</label><a href="http://verified.weibo.com/verify" target="_blank"><i class="W_icon icon_approve"></i><i class="W_icon icon_approve_gold"></i><i class="W_icon icon_approve_co"></i></a></td><td><input type="checkbox" node-type="hideDarenIcon"><label>微博达人标识</label><a href="http://club.weibo.com/intro" target="_blank"><i class="W_icon icon_club"></i></a></td></tr><tr><td><input type="checkbox" node-type="hideMemberIcon"><label>微博会员标识</label><a href="http://vip.weibo.com/" target="_blank"><i class="W_icon icon_member"></i></a></td><td><input type="checkbox" node-type="hideVgirlIcon"><label>微博女郎标识</label><a href="http://vgirl.weibo.com/" target="_blank"><i class="W_icon icon_vlady"></i></a></td></tr><tr><td><input type="checkbox" node-type="hideTaobaoIcon"><label>淘宝商户</label><a href="http://e.weibo.com/taobao/introduce" target="_blank"><i class="W_icon icon_taobao"></i><i class="W_icon icon_tmall"></i></a></td><td><input type="checkbox" node-type="hideGongyiIcon"><label>微公益</label><a href="http://gongyi.weibo.com/" target="_blank"><i class="W_icon icon_gongyi"></i></a></td></tr><tr><td><input type="checkbox" node-type="hideHongbaoIcon"><label>让红包飞</label><a href="http://chunjie.hongbao.weibo.com/hongbao2017" target="_blank"><i class="W_icon icon_redpack"></i><i class="W_icon icon_wealth"></i></a></td><td><input type="checkbox" node-type="hidePaiIcon"><label>随手拍2017</label><a href="http://huodong.weibo.com/pai2017" target="_blank"><i class="W_icon icon_suishoupai2014"></i></a></td></tr><tr><td><input type="checkbox" node-type="hideTravelIcon"><label>带着微博去旅行</label><a href="http://huodong.weibo.com/travel2017" target="_blank"><i class="W_icon icon_airball"></i></a></td></tr><tr class="wbpRowSpacing"><td><input type="checkbox" node-type="hideProfCover"><label>封面图(个人主页)</label></td><td><input type="checkbox" node-type="hideProfStats"><label>关注/粉丝/微博数(个人主页)</label></td></tr><tr><td><input type="checkbox" node-type="hideRelation"><label>关注/粉丝/微关系(个人主页)</label></td><td><input type="checkbox" node-type="hideAlbum"><label>微相册(个人主页)</label></td></tr><tr class="wbpRowSpacing"><td colspan="2"><input type="checkbox" node-type="hideFeedRecom"><label>相关推荐:单条微博右边栏</label></td></tr></tbody></table><p style="margin-top: 15px"><a href="javascript:void(0);" class="W_btn_b" node-type="hideAll"><span>全选</span></a><a href="javascript:void(0);" class="W_btn_b" node-type="hideInvert" style="margin-left: 5px"><span>反选</span></a></p></div><div node-type="tabModify" style="display: none"><p><input type="checkbox" node-type="squareAvatar"><label>使用方形头像</label></p><p><input type="checkbox" node-type="moveSrcToBtm"><label>微博来源移动至微博底部</label></p><p style="margin-left: 20px"><input type="checkbox" node-type="unwrapText"><label>微博作者与正文间不折行</label></p><p style="margin-left: 20px"><input type="checkbox" node-type="compactFeedToolbar"><label>使用紧凑型(V5样式)微博工具栏(收藏 | 转发 | 评论 | 赞)</label></p><p><input type="checkbox" node-type="noHomeRightBar"><label>去除首页右边栏</label></p><p><input type="checkbox" node-type="noHomeMargins"><label>在首页使用紧凑版式(去除卡片间空隙)</label></p><p><input type="checkbox" node-type="noHotYellowTags"><label>禁止弹出“有新的热门微博”等提示</label></p><p><input type="checkbox" node-type="showAllArticleText"><label>显示未关注作者的长微博全文</label></p><p><input type="checkbox" node-type="showAllText"><label>展开字数超长的微博内容</label></p><p><input type="checkbox" node-type="showAllGroups"><label>展开分组栏中的所有分组</label></p><p><input type="checkbox" node-type="showAllMsgNav"><label>在左边栏增加消息导航(“评论”、“私信”等)</label></p><p><input type="checkbox" node-type="showAllSonFeeds"><label>展开所有子微博(“还有?条对原微博的转发”)</label></p><p><input type="checkbox" node-type="directBigImg"><label>点击“查看大图”或“查看图片”直接打开大图</label></p><p><input type="checkbox" node-type="directAllFeeds"><label>进入未关注人主页时默认查看全部微博</label></p><p><input type="checkbox" node-type="noDefaultGroupPub"><label>禁止在浏览分组时默认发布新微博到该分组</label></p><p><input type="checkbox" node-type="clearDefTopic"><label title="关闭此选项后需要刷新页面生效">清除微博发布框中的默认话题</label></p><div style="margin-top: 15px"><p><input type="checkbox" node-type="smallImgLayout"><label>启用小图版式(自定义微博配图尺寸)</label></p><table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top: 3px"><tbody><tr><td style="width: 60px; padding-left: 19px">插图尺寸:</td><td><div class="wbpInput" style="width: 40px"><input type="text" node-type="customImgSize" class="input"></div></td><td style="width: 50px">总宽度:</td><td><div class="wbpInput" style="width: 40px"><input type="text" node-type="customTotalWidth" class="input"></div></td><td style="width: 100px">视频缩略图尺寸:</td><td><div class="wbpInput" style="width: 40px"><input type="text" node-type="customVideoSize" class="input"></div></td></tr></tbody></table></div><div style="margin-top: 10px">在<input type="checkbox" node-type="readerModeIndex" style="margin: 0 2px 0 8px"><label>我的首页</label><input type="checkbox" node-type="readerModeProfile" style="margin: 0 2px 0 8px"><label style="margin-right: 8px">个人主页</label>启用极简阅读模式<span style="color: red">(可按F8切换)</span><table width="100%" border="0" cellspacing="0" cellpadding="0" style="margin-top: 3px"><tbody><tr><td style="width: 85px; padding-left: 19px">宽度(像素):</td><td><div class="wbpInput" style="width: 40px"><input type="text" node-type="readerModeWidth" class="input"></div></td></tr></tbody></table></div><div style="margin-top: 10px">设置<input type="checkbox" node-type="overrideMyBack" style="margin: 0 2px 0 8px"><label>我的首页</label><input type="checkbox" node-type="overrideOtherBack" style="margin: 0 2px 0 8px"><label style="margin-right: 8px">个人主页</label>透明背景色<div class="wbpInput wbpInlineInput" style="width: 190px" title="最后一个参数为透明度,0为全透明,1为不透明"><input type="text" node-type="backColor" class="input"></div></div><div style="margin-top: 10px">覆盖<input type="checkbox" node-type="overrideMySkin" style="margin: 0 2px 0 8px"><label>我的首页</label><input type="checkbox" node-type="overrideOtherSkin" style="margin: 0 2px 0 8px"><label style="margin-right: 8px">个人主页</label>模板设置为<div class="wbpInput wbpInlineInput" style="width: 80px" title="普通模板为“skin+三位数字编号”,如skin012\n会员专属模板为“skinvip+三位数字编号”,如skinvip012\n默认模板为default"><input type="text" node-type="skinID" class="input"></div>(仅自己可见)</div><p style="margin-top: 10px"><input type="checkbox" node-type="useCustomStyles"><label><span style="color: red">自定义样式</span>(CSS):可用于屏蔽模块、改造版面,</label><a href="https://bitbucket.org/salviati/weibo-cleaner/wiki/CustomCSS" target="_blank">点此查看示例</a></p><textarea node-type="customStyles" rows="6" style="margin-top: 5px"></textarea></div><div node-type="tabSettings" style="display: none"><p><input type="checkbox" node-type="updateNotify"><label>更新后首次使用时显示新功能</label></p><div class="clearfix" style="margin-top: 8px"><div style="float: left; width: 375px"><p>当前账号的设置信息在以下文本框中,您可以将其复制到其它位置保存。导入设置时,请将设置信息粘贴到文本框中,然后点击“导入”。</p></div><a href="javascript:void(0)" class="W_btn_b" node-type="import" style="float: right; margin-top: 6px"><span>导入</span></a></div><textarea node-type="settingsString" rows="10"></textarea></div></div></div><p style="margin-top: 10px"><a href="javascript:void(0);" class="W_btn_a" node-type="OK"><span>确定</span></a><a href="javascript:void(0);" class="W_btn_b" node-type="cancel" style="margin-left: 10px"><span>取消</span></a></p></div>', events;
461 dialog = STK.ui.dialog({isHold: true});
462 dialog.setTitle('“眼不见心不烦”(v2.6.1)设置');
463 // 首页与主页API不一致
464 if (dialog.getDom) {
465 content = STK.ui.mod.layer(HTML);
466 dialog.setContent(content.getOuter());
467 events = STK.core.evt.delegatedEvent(content.getDom('tabs'));
468 } else {
469 //content = STK.ui.mod.layer({template: HTML, appendTo: null});
470 dialog.setContent(HTML);
471 events = STK.core.evt.delegatedEvent(dialog.getDomList(true).tabs); // true用于更新DOM缓存(只需做一次)
472 }
473 // 修改屏蔽提示颜色事件
474 bind('tipBackColor', function () {
475 getDom('tipSample').style.backgroundColor = this.value;
476 }, 'blur');
477 bind('tipTextColor', function () {
478 getDom('tipSample').style.borderColor = this.value;
479 getDom('tipSample').style.color = this.value;
480 }, 'blur');
481 // 添加关键词按钮点击事件
482 events.add('add', 'click', function (action) {
483 addKeywords(action.data.list, action.data.text);
484 });
485 // 清空关键词按钮点击事件
486 events.add('clear', 'click', function (action) {
487 getDom(action.data.list).innerHTML = '';
488 });
489 // 删除关键词事件
490 events.add('remove', 'click', function (action) {
491 $.remove(action.el);
492 });
493 // 添加用户按钮点击事件
494 events.add('addUser', 'click', function (action) {
495 addUsers(action.data.list, action.data.text);
496 });
497 // 复选框标签点击事件
498 bind('outer', function (event) {
499 var node = event.target;
500 // 标签下可能有span等元素
501 if (node.parentNode && node.parentNode.tagName === 'LABEL') {
502 node = node.parentNode;
503 }
504 if (node.tagName === 'LABEL') {
505 event.preventDefault();
506 event.stopPropagation();
507 if (node.getAttribute('for')) {
508 // 有for属性则使用之
509 getDom(node.getAttribute('for')).click();
510 } else {
511 // 默认目标在标签之前(同级)
512 node.previousSibling.click();
513 }
514 }
515 });
516 // 标签点击事件
517 bind('tabHeaders', function (event) {
518 var node = event.target;
519 if (node && node.tagName === 'A') {
520 node.className = 'current';
521 getDom(node.getAttribute('tab')).style.display = '';
522 Array.prototype.forEach.call(this.childNodes, function (child) {
523 if (node !== child) {
524 child.className = '';
525 getDom(child.getAttribute('tab')).style.display = 'none';
526 }
527 });
528 }
529 });
530 // 点击“设置导入/导出”标签时更新内容
531 bind('tabHeaderSettings', exportSettings);
532 // 点击“用户”标签时载入用户黑名单头像
533 bind('tabHeaderUser', function () { addUsers('userBlacklist'); });
534 bind('hideAll', function () {
535 for (var module in $page.modules) {
536 getDom('hide' + module).checked = true;
537 }
538 });
539 bind('hideInvert', function () {
540 for (var module in $page.modules) {
541 var item = getDom('hide' + module);
542 item.checked = !item.checked;
543 }
544 });
545 // 对话框按钮点击事件
546 bind('import', function () {
547 var options = new Options();
548 if (options.load(getDom('settingsString').value)) {
549 importSettings(options);
550 alert('设置导入成功!');
551 } else {
552 alert('设置导入失败!\n设置信息格式有问题。');
553 }
554 });
555 bind('OK', function () {
556 $options = exportSettings();
557 $options.save();
558 $filter();
559 $page();
560 dialog.hide();
561 shown = false;
562 });
563 bind('cancel', function () {
564 dialog.hide();
565 shown = false;
566 });
567 return true;
568 };
569 // 显示设置窗口
570 var show = function () {
571 if (!dialog && !createDialog()) {
572 return;
573 }
574 shown = true;
575 importSettings($options);
576 if (getDom('tabHeaderUser').classList.contains('current')) {
577 addUsers('userBlacklist');
578 }
579 dialog.show().setMiddle();
580 };
581 show.shown = function () {
582 return shown;
583 };
584
585 return show;
586})();
587
588// 关键词过滤器
589var $filter = (function () {
590 var forwardFeeds = {}, floodFeeds = {};
591 // 搜索指定文本中是否包含列表中的关键词
592 var search = function (str, key) {
593 var text = str.toLowerCase(), keywords = $options[key];
594 if (str === '' || keywords.length === 0) { return ''; }
595 var matched = keywords.filter(function (keyword) {
596 if (!keyword) { return false; }
597 if (keyword.length > 2 && keyword.charAt(0) === '/' && keyword.charAt(keyword.length - 1) === '/') {
598 try {
599 // 尝试匹配正则表达式
600 return (RegExp(keyword.slice(1, -1)).test(str));
601 } catch (e) { }
602 } else {
603 return keyword.split('+').every(function (k) { return text.indexOf(k.toLowerCase()) !== -1; });
604 }
605 return false;
606 });
607 return matched.length ? matched[0] : '';
608 };
609 // 获取微博正文
610 var getText = function (content) {
611 var node = content.firstChild, text = '';
612 // 只保留ID(如果用户要求)与话题,去掉其它链接(如淘宝链接、短链接、地点等)
613 while (node) {
614 if (node.nodeType === Node.TEXT_NODE) {
615 text += node.nodeValue.trim();
616 } else if (node.nodeType === Node.ELEMENT_NODE) {
617 if (node.tagName === 'A' && node.getAttribute('extra-data') === 'type=topic') { // 话题
618 text += node.textContent;
619 } else if ($options.filterName && node.tagName === 'A' && node.hasAttribute('usercard')) { // 用户ID
620 text += node.textContent;
621 } else if ($options.filterSmiley && node.tagName === 'IMG' && node.getAttribute('type') === 'face') {
622 text += node.getAttribute('alt');
623 }
624 }
625 node = node.nextSibling;
626 }
627 return text;
628 };
629 // 过滤微博来源
630 var searchSource = function (source, keywords) {
631 if (!source) {
632 source = '';
633 } else {
634 // 过长的应用名称会被压缩,完整名称存放在title属性中
635 source = source.title || source.textContent;
636 }
637 return search(source, keywords);
638 };
639 // 过滤单条微博
640 var apply = function (feed) {
641 if (feed.firstChild && feed.firstChild.className === 'wbpTip') {
642 // 已被灰名单屏蔽过,移除屏蔽提示和分隔线
643 feed.removeChild(feed.firstChild);
644 }
645 var mid = feed.getAttribute('mid');
646 if (!mid) { return false; } // 动态没有mid
647 var scope = $.scope(), isForward = (feed.getAttribute('isforward') === '1');
648 var author, content, source, fwdAuthor, fwdContent, fwdSource;
649 if (scope === 3) { scope = 1; } // 热门微博的展现形式类似主页
650 // V6版单条微博页面与用户主页结构类似,不要屏蔽
651 if (scope === 2 && feed.parentNode.getAttribute('node-type') === 'feedconfig') { return false; }
652 if (scope === 1 && feed.getAttribute('feedtype') === 'subfeed') { // “还有?条对原微博的转发”
653 author = feed.querySelector('.WB_detail>.WB_text>a[usercard]');
654 content = feed.querySelector('.WB_detail>.WB_text>[node-type="feed_list_content"]');
655 source = feed.querySelector('.WB_detail>.WB_func>.WB_from>a[date]+a');
656 } else {
657 author = (scope === 1) ? feed.querySelector('.WB_detail>.WB_info>a[usercard]') : null;
658 // 对于字数超长微博,优先采用展开后的完整内容(如果有)
659 content = feed.querySelector('.WB_detail>.WB_text[node-type="feed_list_content_full"]') || feed.querySelector('.WB_detail>.WB_text[node-type="feed_list_content"]');
660 source = feed.querySelector('.WB_detail>.WB_from>a[date]+a');
661 fwdAuthor = feed.querySelector('.WB_feed_expand .WB_info>a[usercard]');
662 fwdContent = feed.querySelector('.WB_feed_expand .WB_text');
663 fwdSource = feed.querySelector('.WB_feed_expand .WB_func .WB_from>a[date]+a');
664 }
665 var uid = author ? author.getAttribute('usercard').match(/id=(\d+)/)[1] : null,
666 fuid = fwdAuthor ? fwdAuthor.getAttribute('usercard').match(/id=(\d+)/)[1] : null,
667 text = '';
668
669 if (!content) { return false; }
670 if (scope === 1 && $options.filterName) { text = '@' + author.getAttribute('nick-name') + ': '; }
671 text += getText(content);
672 if (isForward && fwdAuthor && fwdContent) {
673 // 转发内容
674 text += '////' + ($options.filterName ? '@' + fwdAuthor.getAttribute('nick-name') + ': ' : '') + getText(fwdContent);
675 }
676
677 // 处理子微博
678 if (feed.querySelector('.WB_feed_together')) {
679 var sonFeeds = feed.querySelectorAll('.WB_feed_detail[feedtype="subfeed"]'),
680 sonFeedsLeft = sonFeeds.length - Array.prototype.filter.call(sonFeeds, apply).length;
681 if (sonFeedsLeft === 0) {
682 feed.querySelector('.WB_feed_together').style.display = 'none'; // 隐藏整个子微博栏目
683 } else {
684 feed.querySelector('.WB_feed_together').style.display = '';
685 feed.querySelector('.WB_feed_together [node-type="followNum"]').innerHTML = sonFeedsLeft;
686 }
687 }
688
689 if ($options.filterPaused || // 暂停屏蔽
690 ($options.filterOthersOnly && feed.querySelector('.WB_screen a[action-type="feed_list_delete"]')) || // 不要屏蔽自己的微博(判据:工具栏是否有“删除”)
691 search(text, 'whiteKeywords')) { // 白名单条件
692 } else if ((function () { // 黑名单条件
693 // 屏蔽推广微博
694 if (scope === 1 && $options.filterPromotions && feed.getAttribute('feedtype') === 'ad') {
695 return true;
696 }
697 // 屏蔽热门微博
698 if (scope === 1 && $options.filterHot && feed.getAttribute('feedtype') === 'top') {
699 return true;
700 }
701 // 屏蔽好友赞过的微博(首页和个人主页)
702 if ($options.filterLiked && (
703 (scope === 1 && feed.querySelector('.WB_cardtitle_b [suda-uatrack*="key=insert_like"]')) ||
704 (scope === 2 && feed.querySelector('.WB_face a[action-type="follow"]')))) {
705 return true;
706 }
707 // 屏蔽关注话题推荐的微博
708 if (scope === 1 && $options.filterTopic && feed.querySelector('.WB_cardtitle_b .main_title>a[href*="//weibo.com/p/"]')) {
709 return true;
710 }
711 // 屏蔽已删除微博的转发(是转发但无转发作者)
712 if ($options.filterDeleted && isForward && !fwdAuthor) {
713 return true;
714 }
715 // 用户黑名单
716 if ((scope === 1 && author && $options.userBlacklist.indexOf(uid) !== -1) ||
717 (isForward && fwdAuthor && (scope === 1 || fuid !== $.oid) && $options.userBlacklist.indexOf(fuid) !== -1)) {
718 return true;
719 }
720 // 屏蔽淘宝和天猫链接微博
721 if ($options.filterTaobao && feed.querySelector('a[href*="tb.cn"] i.icon_cd_tb, a[href*="tb.cn"] i.icon_cd_tmall')) {
722 return true;
723 }
724 // 屏蔽指定来源
725 if (searchSource(source, 'sourceKeywords') ||
726 (isForward && searchSource(fwdSource, 'sourceKeywords'))) {
727 return true;
728 }
729 // 反刷屏(屏蔽同一用户大量发帖)
730 if ($options.filterFlood && uid && floodFeeds[uid]) {
731 if (floodFeeds[uid].length >= Number($options.maxFlood) && floodFeeds[uid].indexOf(mid) === -1) {
732 return true;
733 }
734 }
735 // 在微博内容中搜索屏蔽关键词
736 if (search(text, 'blackKeywords')) {
737 return true;
738 }
739 return false;
740 })()) {
741 feed.style.display = 'none'; // 直接隐藏,不显示屏蔽提示
742 return true;
743 } else { // 灰名单条件
744 // 搜索来源灰名单
745 var sourceKeyword = searchSource(source, 'sourceGrayKeywords'),
746 keyword = search(text, 'grayKeywords');
747 if (!sourceKeyword && isForward) {
748 sourceKeyword = searchSource(fwdSource, 'sourceGrayKeywords');
749 }
750 if (keyword || sourceKeyword) {
751 // 找到了待隐藏的微博
752 var authorClone;
753 if (scope === 1) {
754 // 添加隐藏提示链接
755 authorClone = author.cloneNode(false);
756 authorClone.textContent = '@' + author.getAttribute('nick-name');
757 authorClone.className = '';
758 }
759 var showFeedLink = document.createElement('a');
760 showFeedLink.href = 'javascript:void(0)';
761 showFeedLink.className = 'wbpTip';
762 var keywordLink = document.createElement('a');
763 keywordLink.href = 'javascript:void(0)';
764 keywordLink.className = 'wbpTipKeyword';
765 keywordLink.textContent = keyword || sourceKeyword;
766 if (scope === 1) {
767 showFeedLink.appendChild(document.createTextNode('本条来自'));
768 showFeedLink.appendChild(authorClone);
769 showFeedLink.appendChild(document.createTextNode('的微博因'));
770 } else if (scope === 2) {
771 showFeedLink.appendChild(document.createTextNode('本条微博因'));
772 }
773 showFeedLink.appendChild(document.createTextNode(keyword ? '内容包含“' : '来源名称包含“'));
774 showFeedLink.appendChild(keywordLink);
775 showFeedLink.appendChild(document.createTextNode('”而被隐藏,点击显示'));
776 feed.insertBefore(showFeedLink, feed.firstChild);
777 return false; // 灰名单不作为屏蔽处理
778 }
779 }
780 // 显示微博并记录
781 feed.style.display = '';
782 if (!$options.filterPaused) {
783 if ($options.filterFlood && uid) {
784 if (!floodFeeds[uid]) {
785 floodFeeds[uid] = [];
786 }
787 if (floodFeeds[uid].indexOf(mid) === -1) {
788 floodFeeds[uid].push(mid);
789 }
790 }
791 }
792 return false;
793 };
794 // 过滤所有微博
795 var applyToAll = function () {
796 // 过滤所有微博
797 if ($.scope()) {
798 forwardFeeds = {}; floodFeeds = {};
799 Array.prototype.forEach.call(document.querySelectorAll('.WB_feed_type'), apply);
800 }
801 };
802 // 屏蔽提示相关事件的冒泡处理
803 var bindTipOnClick = function (node) {
804 if (!node) { return; }
805 $.click(node, function (event) {
806 var node = event.target;
807 if (node && node.tagName === 'A') {
808 if (node.className === 'wbpTipKeyword') {
809 $dialog();
810 event.stopPropagation(); // 防止事件冒泡触发屏蔽提示的onclick事件
811 } else if (node.className === 'wbpTip') {
812 $.remove(node);
813 }
814 }
815 });
816 };
817
818 // 处理动态载入的微博
819 if ($.scope()) {
820 bindTipOnClick($.select('.WB_feed'));
821 }
822 // 点击“查看大图”事件拦截处理
823 document.addEventListener('click', function (event) {
824 if (!$options.directBigImg || !event.target) { return true; }
825 var actionType = event.target.getAttribute('action-type'), actionData = event.target.getAttribute('action-data'), actionDataList = {};
826 if (actionType !== 'widget_commentPhotoView' && actionType !== 'images_view_tobig' && actionType !== 'widget_photoview') { return true; }
827 if (actionData) {
828 actionData.split("&").forEach(function (item) {
829 actionDataList[item.split('=')[0]] = unescape(item.split('=')[1]);
830 });
831 }
832 if (actionType === 'widget_commentPhotoView' && actionDataList.pid) {
833 // 评论图片
834 window.open('http://ww4.sinaimg.cn/large/' + actionDataList.pid + '.jpg', '_blank');
835 event.stopPropagation();
836 } else if ((actionType === 'images_view_tobig' || actionType === 'widget_photoview') &&
837 actionDataList.pid && actionDataList.mid && actionDataList.uid) {
838 // 微博配图
839 window.open('http://photo.weibo.com/' + actionDataList.uid +
840 '/wbphotos/large/mid/' + actionDataList.mid +
841 '/pid/' + actionDataList.pid, '_blank');
842 event.stopPropagation();
843 } else if (actionType === 'widget_photoview' && event.target.getAttribute('alt')) {
844 // 图片链接
845 window.open(event.target.getAttribute('alt'));
846 event.stopPropagation();
847 }
848 }, true);
849 // 使用事件捕捉以尽早触发事件,避免与新浪自带事件撞车
850 document.addEventListener('DOMNodeInserted', function (event) {
851 var node = event.target;
852 if ($.scope() === 0 || node.tagName !== 'DIV') { return; }
853 if (node.classList.contains('WB_feed_type')) {
854 // 处理动态载入的微博
855 apply(node);
856 } else if (node.classList.contains('W_loading')) {
857 var requestType = node.getAttribute('requesttype');
858 // 仅在搜索和翻页时需要初始化反刷屏/反版聊记录
859 // 其它情况(新微博:newFeed,同页接续:lazyload)下不需要
860 if (requestType === 'search' || requestType === 'page') {
861 forwardFeeds = {}; floodFeeds = {};
862 }
863 } else if (node.classList.contains('WB_feed') || node.querySelector('.WB_feed')) {
864 // 微博列表作为pagelet被一次性载入
865 bindTipOnClick(node);
866 applyToAll();
867 } else if (node.classList.contains('WB_text') && node.getAttribute('node-type') === 'feed_list_content_full') {
868 // 字数超长微博的完整部分展开时才会载入,需重新处理
869 do { node = node.parentNode; } while (!node.classList.contains('WB_feed_type'));
870 apply(node);
871 }
872 }, false);
873
874 return function (feed) {
875 if (feed) {
876 apply(feed);
877 } else {
878 applyToAll();
879 }
880 };
881})();
882
883// 修改页面
884var $page = (function () {
885 // 模块屏蔽设置
886 var modules = {
887 Ads : '#plc_main [id^="v6_pl_rightmod_ads"], div[ad-data], #v6_pl_ad_bottomtip, .WB_ad_tm2015',
888 Stats : '#v6_pl_rightmod_myinfo .W_person_info { height: auto !important } #v6_pl_rightmod_myinfo .user_atten',
889 Level : '.W_icon_level',
890 HotSearch : '.WB_global_nav .gn_search_v2 > .placeholder',
891 ToMe : '#v6_pl_leftnav_group .lev > a[groupnm="page_group_to_me"]',
892 HotWeibo : '#v6_pl_leftnav_group .lev_line_v2, #v6_pl_leftnav_group .lev_line_v2 + .lev_Box',
893 Hongbao : '#v6_pl_rightmod_hongbao',
894 Friends : '#v6_pl_leftnav_group .lev > a[isfriends]',
895 Topic : '#trustPagelet_zt_hottopic', // 动态右边栏
896 Member : '#v6_trustPagelet_recom_member',
897 MusicRecom : '#v6_pl_rightmod_rank',
898 MovieRecom : '#trustPagelet_recom_movie', // 动态右边栏
899 AttFeed : '#v6_pl_rightmod_attfeed',
900 Notice : '#v6_pl_rightmod_noticeboard',
901 Footer : '#plc_bot .WB_footer',
902 MusicPlayer : '.PCD_mplayer',
903 RecommendedTopic : '#v6_pl_content_publishertop div[node-type="recommendTopic"]',
904 CommentTip : 'div[node-type="feed_privateset_tip"]',
905 MemberTip : 'div[node-type="feed_list_shieldKeyword"]',
906 MemberCover : '.WB_feed_vipcover .WB_feed_detail { background-image: none !important } .WB_feed_vipcover .WB_feed_detail { padding-top: 10px !important } .WB_feed_vipcover .WB_vipcover',
907 TimelineMods : '.FRAME_main .WB_feed .WB_feed_type:not([mid]), .FRAME_page .WB_feed .WB_feed_type:not([mid])',
908 TopicCard : '.WB_feed_spec[action-data*="huati.weibo.com"]',
909 LocationCard : '.WB_feed_spec[exp-data*="value=1022-place"]',
910 AppCard : '.WB_feed_spec[exp-data*="value=1022-app"]',
911 IMNews : '.webim_news',
912 RecomFeed : 'div[node-type="feed_list_recommend"], div[node-type="recommfeed"]',
913 ProfCover : '#Pl_Official_Headerv6__1 .PCD_header .S_shadow { background: transparent !important } #Pl_Official_Headerv6__1 .cover_wrap',
914 ProfStats : '.WB_frame_b .PCD_counter',
915 Relation : '.WB_frame_b .PCD_user_a',
916 Album : '.WB_frame_b .PCD_photolist',
917 FeedRecom : '.WB_frame_b > div[id^="Pl_Core_RecommendFeed"]',
918 MemberIcon : '.W_icon[class*="icon_member"], .icon_member_dis, .W_icon_vipstyle',
919 VerifyIcon : '.icon_approve, .icon_approve_gold, .icon_approve_co',
920 DarenIcon : '.icon_club',
921 VgirlIcon : '.icon_vlady',
922 TaobaoIcon : '.icon_taobao, .icon_tmall',
923 GongyiIcon : '.W_icon[class*="icon_gongyi"]',
924 HongbaoIcon : '.icon_redpack, .icon_wealth',
925 PaiIcon : '.icon_suishoupai2014',
926 TravelIcon : '.icon_airball',
927 };
928 // 显示设置链接
929 var showSettingsBtn = function (node) {
930 if (!$('wbpShowSettings')) {
931 if (!node) {
932 node = $.select('.WB_global_nav .gn_topmenulist_set[node-type="accountLayer"] > ul');
933 if (!node) { return false; }
934 }
935 var tab = document.createElement('li');
936 tab.id = 'wbpShowSettings';
937 tab.innerHTML = '<a href="javascript:void(0)" style="color: blue">眼不见心不烦</a>';
938 $.click(tab, $dialog);
939 node.insertBefore(tab, node.firstChild);
940 node.parentNode.style.width = 'auto';
941 }
942 return true;
943 };
944 // 极简阅读模式(仅在个人首页生效)
945 var toggleReaderMode = function () {
946 var readerModeStyles = $('wbpReaderModeStyles');
947 if ($options.readerModeIndex || $options.readerModeProfile) {
948 if (!readerModeStyles) {
949 readerModeStyles = document.createElement('style');
950 readerModeStyles.type = 'text/css';
951 readerModeStyles.id = 'wbpReaderModeStyles';
952 document.head.appendChild(readerModeStyles);
953 }
954 var width = Number($options.readerModeWidth);
955 readerModeStyles.innerHTML = '';
956 if ($options.readerModeIndex) {
957 readerModeStyles.innerHTML += '.FRAME_main #plc_top, .FRAME_main .WB_main_l, .FRAME_main .WB_main_r, .FRAME_main .WB_main_c>div:not(#v6_pl_content_homefeed), .FRAME_main #v6_pl_content_homefeed .WB_tab_a, .FRAME_main #plc_bot .WB_footer { display: none }\n' +
958 '.FRAME_main .WB_frame { background-color: transparent !important; width: ' + width + 'px !important }\n' +
959 '.FRAME_main #plc_main, .FRAME_main .WB_main_c { width: 100% !important; margin-right: 0 !important }\n' +
960 '.FRAME_main #base_scrollToTop { margin-left: ' + (width/2) + 'px !important }\n';
961 }
962 if ($options.readerModeProfile) { // 个人主页
963 if ($.config.location.slice(-4) === 'home') { // 排除单条微博页面
964 readerModeStyles.innerHTML += '.FRAME_page.B_page #pl_common_top, .FRAME_page.B_page .WB_frame_a, .FRAME_page.B_page .WB_frame_b, .FRAME_page.B_page .WB_frame_c>div:not([id^="Pl_Official_MyProfileFeed"]):not([id^="Pl_Official_TimeBase"]), .FRAME_main #v6_pl_content_homefeed .WB_tab_a, .FRAME_page.B_page #pl_common_footer>:not(#base_scrollToTop) { display: none }\n' +
965 '.FRAME_page.B_page .WB_frame { width: ' + width + 'px !important; padding-top: 0 !important }\n' +
966 '.FRAME_page.B_page #plc_main, .FRAME_page.B_page .WB_frame_c { width: 100% !important; margin-right: 0 !important }\n' +
967 '.FRAME_page.B_page .WB_timeline, .FRAME_page.B_page #base_scrollToTop { margin-left: ' + (width/2) + 'px !important }';
968 }
969 }
970 if (!$options.readerModeTip && (
971 ($.scope() === 1 && $options.readerModeIndex) ||
972 ($.scope() === 2 && $options.readerModeProfile))) { // TODO: 新版微博单条页面不弹出提示
973 alert('欢迎进入极简阅读模式!\n\n您可以按【F8】键快速开关本模式,也可以在“眼不见心不烦”插件设置“改造版面”页进行选择。');
974 $options.readerModeTip = true;
975 $options.save(true);
976 }
977 } else if (readerModeStyles) {
978 $.remove(readerModeStyles);
979 }
980 };
981 // 覆盖当前模板设置
982 var overrideSkin = function () {
983 var formerStyle = $('custom_style') || $('skin_style') || document.head.querySelector('link:not([id])[href*="/skin/"]'),
984 skinCSS = $('wbpOverrideSkin');
985 if (!formerStyle) { return; }
986 if (($.uid === $.config.oid && $options.overrideMySkin) ||
987 ($.uid !== $.config.oid && $options.overrideOtherSkin)) {
988 if (!skinCSS) {
989 skinCSS = document.createElement('link');
990 skinCSS.id = 'wbpOverrideSkin';
991 skinCSS.type = 'text/css';
992 skinCSS.rel = 'stylesheet';
993 skinCSS.charset = 'utf-8';
994 document.head.insertBefore(skinCSS, formerStyle);
995 }
996 skinCSS.href = $.config.cssPath + 'skin/' + $options.skinID + '/skin.css?version=' + $.config.version;
997 formerStyle.disabled = true;
998 } else if (skinCSS) {
999 $.remove(skinCSS);
1000 formerStyle.disabled = false;
1001 }
1002 };
1003 // 2013年6月起右边栏模块不再有固定ID,为其打上ID
1004 var tagRightbarMods = function (rightBar) {
1005 if (!rightBar) { return; }
1006 var identifiers = {
1007 '[change-data*="hottopic_r2"]' : 'Topic',
1008 '.WB_cardmore[href*="movie.weibo.com"], .main_title>a[href*="taobao.com/market/dianying/"]' : 'MovieRecom'
1009 }, mods = rightBar.querySelectorAll('.WB_cardwrap');
1010 for (var i = 0; i < mods.length; ++i) {
1011 for (var id in identifiers) {
1012 if (mods[i].querySelector(id)) {
1013 mods[i].id = modules[identifiers[id]].slice(1);
1014 break;
1015 }
1016 }
1017 }
1018 };
1019 // 屏蔽模块
1020 var hideModules = function () {
1021 var cssText = '';
1022 $options.hideMods.forEach(function (module) {
1023 if (modules[module]) {
1024 cssText += modules[module] + ' { display: none !important }\n';
1025 }
1026 });
1027 if ($options.hideMods.indexOf('ProfCover') !== -1) { // 屏蔽封面时的特别处理
1028 cssText += '.profile_top { min-height: ' + ($options.hideMods.indexOf('ProfStats') === -1 ? 250 : 200) + 'px }\n';
1029 }
1030 // 屏蔽提示相关CSS
1031 var tipBackColor = $options.tipBackColor, tipTextColor = $options.tipTextColor;
1032 cssText += '.wbpTip:not(:hover) { background-color: ' + tipBackColor + '; border-color: ' + tipTextColor + '; color: ' + tipTextColor + '; }';
1033 // 更新CSS
1034 var styles = $('wbpModuleStyles');
1035 if (!styles) {
1036 styles = document.createElement('style');
1037 styles.type = 'text/css';
1038 styles.id = 'wbpModuleStyles';
1039 document.head.appendChild(styles);
1040 }
1041 styles.innerHTML = cssText + '\n';
1042 // 单独处理“为你推荐”弹窗
1043 if ($options.hideMods.indexOf('FollowGuide') !== -1) {
1044 // 载入页面时,如果DOM中包含#pl_guide_homeguide > div[node-type="follow_dialog"]则会弹出
1045 // 如果能抢在pl.guide.homeguide.index()之前去除,可以避免弹窗出现
1046 $.remove($.select('#pl_guide_homeguide > div[node-type="follow_dialog"]'));
1047 // 如果弹窗已经显示,则关闭之
1048 //var closeBtn = $.select('.layer_userguide_brief .W_close');
1049 //if (closeBtn) { closeBtn.click(); }
1050 // 模拟点击关闭按钮会导致页面刷新,改为去除弹窗DOM及其下的overlay
1051 var followGuide = $.select('.layer_userguide_brief');
1052 if (followGuide) {
1053 while (!followGuide.classList.contains('W_layer')) { followGuide = followGuide.parentNode; }
1054 if (followGuide.previousSibling.style.zIndex === followGuide.style.zIndex) {
1055 $.remove(followGuide.previousSibling); // 覆盖层
1056 }
1057 $.remove(followGuide);
1058 }
1059 }
1060 };
1061 // 禁止默认发布新微博到当前浏览的分组
1062 var disableDefaultGroupPub = function (node) {
1063 if (!$options.noDefaultGroupPub) { return; }
1064 var groupLink = node.querySelector('.limits a[node-type="showPublishTo"]');
1065 if (groupLink) {
1066 groupLink.firstChild.innerHTML = '公开';
1067 groupLink.setAttribute('action-data', 'rank=0');
1068 }
1069 };
1070 // 清除发布框中的默认话题
1071 var clearDefTopic = function () {
1072 if ($options.clearDefTopic && $.scope() === 1) {
1073 var inputBox = $.select('#v6_pl_content_publishertop .send_weibo .input textarea');
1074 if (inputBox && inputBox.hasAttribute('hottopic')) {
1075 // IFRAME载入方式,hotTopic可能尚未启动,直接清除相关属性即可
1076 inputBox.removeAttribute('hottopic');
1077 inputBox.removeAttribute('hottopicid');
1078 // 在发布框中模拟输入,欺骗STK.common.editor.plugin.hotTopic
1079 inputBox.value = 'DUMMY';
1080 inputBox.focus();
1081 inputBox.value = '';
1082 inputBox.blur();
1083 }
1084 }
1085 };
1086 // V6版首页没有消息导航条,人工创建一个
1087 var addMessageNav = function () {
1088 if ($.scope() === 1) {
1089 var groupList = $.select('#v6_pl_leftnav_group .WB_left_nav[node-type="groupList"]');
1090 if (!groupList) { return; }
1091 var msgNavBox = groupList.querySelector('.wbpMessageNav');
1092 if ($options.showAllMsgNav) {
1093 if (!msgNavBox) {
1094 msgNavBox = document.createElement('div');
1095 msgNavBox.className = 'lev_Box lev_Box_noborder wbpMessageNav';
1096 msgNavBox.innerHTML = '<h3 class="lev"><a href="/at/weibo?leftnav=1&wvr=6" class="S_txt1"><span class="levtxt">消息</span></a></h3>\n' +
1097 '<div class="lev"><a href="/comment/inbox?leftnav=1&wvr=6" class="S_txt1"><span class="ico_block"><em class="W_ficon ficon_dot S_ficon">D</em></span><span class="levtxt">评论</span></a></div>\n' +
1098 '<div class="lev"><a href="/messages?leftnav=1&wvr=6" class="S_txt1"><span class="ico_block"><em class="W_ficon ficon_dot S_ficon">D</em></span><span class="levtxt">私信</span></a></div>\n' +
1099 '<div class="lev"><a href="/notesboard?leftnav=1&wvr=6" class="S_txt1"><span class="ico_block"><em class="W_ficon ficon_dot S_ficon">D</em></span><span class="levtxt">未关注人私信</span></a></div>\n';
1100 groupList.insertBefore(msgNavBox, groupList.children[1]);
1101 }
1102 msgNavBox.style.display = '';
1103 } else if (!$options.showAllMsgNav && msgNavBox) {
1104 msgNavBox.style.display = 'none';
1105 }
1106 }
1107 };
1108 // 首次进入用户主页时显示全部微博
1109 var redirectToAllFeeds = function () {
1110 if (!$options.directAllFeeds || $.scope() !== 2) { return; }
1111 (function () {
1112 if (location.href.indexOf('is_') === -1) {
1113 // 尚未出现过滤条件则强制跳转至全部微博
1114 var allFeedsBtn = $.select('li[node-type="tab_all"]');
1115 if (allFeedsBtn) {
1116 allFeedsBtn.click();
1117 return;
1118 } else {
1119 // 跳转标签尚未出现,继续等待
1120 setTimeout(arguments.callee, 100);
1121 }
1122 }
1123 })();
1124 };
1125 // 展开字数超长微博
1126 var expandLongFeeds = function (node) {
1127 if ($options.showAllText && $.scope()) {
1128 var expanders = node.querySelectorAll('.WB_detail>.WB_text[node-type="feed_list_content"]>.WB_text_opt, .WB_expand>.WB_text>.WB_text_opt'),
1129 expand = function (expander) {
1130 STK.ajax({
1131 url: '/p/aj/mblog/getlongtext',
1132 args: STK.queryToJson(expander.getAttribute('action-data')),
1133 method: 'get',
1134 responseType: 'json',
1135 onComplete: function (result) {
1136 if (result.code !== '100000') return;
1137 var feed = expander;
1138 do { feed = feed.parentNode; } while (!feed.classList.contains('WB_feed_type'));
1139 expander.parentNode.innerHTML = result.data.html;
1140 $filter(feed);
1141 },
1142 });
1143 };
1144 for (var i = 0; i < expanders.length; ++i) { expand(expanders[i]); }
1145 }
1146 };
1147 // 显示未关注作者的长微博全文
1148 var showAllArticleText = function (iframe) {
1149 if ($options.showAllArticleText && iframe && iframe.tagName === 'IFRAME' && iframe.name.slice(0,12) === 'articleLayer') {
1150 // 采用以下方法将CSS写入DOM载入完成后的长微博iframe:
1151 // http://stackoverflow.com/questions/24603580/how-can-i-access-the-dom-elements-within-an-iframe/24603642#comment38157462_24603642
1152 var timer, fired = false, doc;
1153 var ready = function () {
1154 if (!fired) {
1155 fired = true;
1156 clearTimeout(timer);
1157 var styles = doc.createElement('style');
1158 styles.type = 'text/css';
1159 styles.innerHTML = '.WB_artical .WB_editor_iframe { height: auto !important } .WB_artical .artical_add_box { display: none !important }\n';
1160 doc.head.appendChild(styles);
1161 }
1162 };
1163 var readyState = function () {
1164 if (this.readyState === 'complete') {
1165 ready();
1166 }
1167 };
1168 iframe.addEventListener('load', function () {
1169 doc = iframe.contentDocument || iframe.contentWindow.document;
1170 ready();
1171 });
1172 var checkLoaded = function () {
1173 doc = iframe.contentDocument || iframe.contentWindow.document;
1174 if (doc.URL.indexOf('about:') !== 0) {
1175 if (doc.readyState === 'complete') {
1176 ready();
1177 } else {
1178 doc.addEventListener('DOMContentLoaded', ready);
1179 doc.addEventListener('readystatechange', readyState);
1180 }
1181 } else {
1182 timer = setTimeout(checkLoaded, 10);
1183 }
1184 };
1185 checkLoaded();
1186 }
1187 };
1188 // 将微博来源移动至底部
1189 var moveSourceToBottom = function (node) {
1190 if ($options.moveSrcToBtm) {
1191 var sources = node.querySelectorAll('.WB_detail>.WB_info+.WB_from');
1192 for (var i = 0; i < sources.length; ++i) { sources[i].parentNode.appendChild(sources[i]); }
1193 }
1194 };
1195 // 禁止弹出“有新的热门微博”等提示
1196 var noHotYellowTags = function (tags) {
1197 if ($options.noHotYellowTags) {
1198 if (!tags) { tags = $('.gn_topmenulist_tips>ul'); if (!tags) { return; } }
1199 var hotTags = tags.querySelectorAll('li>a[suda-data*="value=hot_video_remind"], li>a[suda-data*="value=hot_weibo_remind"]');
1200 for (var i = 0; i < hotTags.length; ++i) {
1201 hotTags[i].parentNode.style.display = 'none';
1202 }
1203 if (hotTags.length > 0 && hotTags.length === tags.childNodes.length) {
1204 // 黄标签中都是推荐内容则全部隐藏
1205 tags.style.display = 'none';
1206 }
1207 }
1208 };
1209 // 用户自定义样式及程序附加样式
1210 var customStyles = function () {
1211 var cssText = '', styles = $('wbpCustomStyles');
1212 if (!styles) {
1213 styles = document.createElement('style');
1214 styles.type = 'text/css';
1215 styles.id = 'wbpCustomStyles';
1216 document.head.appendChild(styles);
1217 }
1218 if ($options.squareAvatar) {
1219 cssText += '.WB_face .face img { border-radius: 0 !important }\n';
1220 }
1221 if ($options.moveSrcToBtm) {
1222 cssText += '.WB_feed_v3 .WB_detail>.WB_feed_expand { margin-bottom: 10px } .WB_detail>.WB_from { padding-top: 5px }';
1223 if ($options.unwrapText) {
1224 cssText += '.WB_detail .WB_info, .WB_detail .WB_text { display: inline } .WB_detail .WB_info:after { content: ": " }\n' +
1225 '.WB_screen .screen_box .W_ficon { width: 16px !important } .WB_screen .screen_box { margin-left: -6px !important }\n' +
1226 '.WB_feed_v3 .WB_face .opt { position: relative !important; right: 0px !important }\n';
1227 }
1228 if ($options.compactFeedToolbar) {
1229 cssText += '.WB_feed_detail { position: static !important }\n' + // 修正紧凑型工具栏无法点击的问题
1230 '.WB_feed_handle { margin-top: -32px } .WB_feed_v3 .WB_feed_handle { margin-top: -30px; margin-bottom: -5px } .WB_feed_handle>.WB_handle { margin-right: 6px } .WB_feed_handle>.WB_handle>ul { border-top: none; text-align: right; margin-right: -1px } .WB_feed_handle>.WB_handle>ul>li { width: auto; display: inline-block; float: none } .WB_feed_handle>.WB_handle>ul>li .line { margin-left: 10px; padding-right: 10px; border-left: none; border-right: 1px solid; line-height: normal; height: auto } .WB_feed_handle>.WB_handle>ul>li .line>[node-type="like_status"]>.W_icon { margin-top: 0 }\n';
1231 }
1232 }
1233 if ($options.showAllArticleText) {
1234 cssText += '.WB_artical .WB_editor_iframe { height: auto !important } .WB_artical .artical_add_box { display: none !important }\n';
1235 }
1236 if ($options.showAllGroups) {
1237 cssText += '#v6_pl_leftnav_group div[node-type="moreList"] { display: block !important } #v6_pl_leftnav_group .levmore { display: none }\n';
1238 }
1239 if ($options.showAllSonFeeds) {
1240 cssText += '.WB_feed_together [node-type="feed_list_wrapForward"] { display: block !important } .WB_feed_together>a[action-type="feed_list_seeAll"], .WB_feed_together>a[action-type="feed_list_foldForward"] { display: none }\n';
1241 }
1242 if ($options.noHomeRightBar) {
1243 cssText += '.FRAME_main .WB_frame .WB_main_r { display: none }\n';
1244 }
1245 if ($options.noHomeMargins) {
1246 cssText += '.FRAME_main .send_weibo, .FRAME_main .WB_tab_a, .FRAME_main .WB_frame .WB_cardwrap { margin-bottom: 0; border-radius: 0 } .FRAME_main .WB_frame .WB_cardwrap.WB_notes[requesttype="newFeed"] { padding-top: 18px } .FRAME_main #home_new_feed_tip { margin-top: 0; padding-top: 0 } .FRAME_main .WB_main_c, .FRAME_main .WB_main_r { margin-right: 0 } .FRAME_main .WB_tab_a .tab li:nth-child(2) .b .b1 em.l i, .FRAME_main .WB_tab_a .tab li:nth-child(2) .t, .FRAME_main .WB_tab_a .tab_box .fr_box { border-radius: 0 } \n';
1247 }
1248 if ($options.noHomeRightBar || $options.noHomeMargins) {
1249 // 右栏宽度230+10;卡片间隙宽度10+10
1250 var reducedWidth = 10 + 230*$options.noHomeRightBar + 10*$options.noHomeMargins;
1251 cssText += '.FRAME_main .WB_frame { width: ' + (1000 - reducedWidth) + 'px } .FRAME_main .WB_frame #plc_main { width: ' + (850 - reducedWidth) + 'px } .FRAME_main .W_gotop { margin-left: ' + (1000 - reducedWidth)/2 + 'px }\n';
1252 }
1253 if ($options.overrideMyBack) {
1254 cssText += '.FRAME_main .S_bg1, .FRAME_main .S_bg2 { background-color: ' + $options.backColor + ' } .FRAME_main .WB_feed_handle .WB_row_line { border-top: none }\n';
1255 }
1256 if ($options.overrideOtherBack) {
1257 cssText += '.FRAME_page .S_bg1, .FRAME_page .S_bg2 { background-color: ' + $options.backColor + ' } .FRAME_page .WB_feed_handle .WB_row_line { border-top: none }\n';
1258 }
1259 if ($options.smallImgLayout) {
1260 if (Number($options.customImgSize) > 0) {
1261 cssText += '.WB_feed_v3 ul.WB_media_a > li.WB_pic { width: ' + $options.customImgSize + 'px !important; height: ' + $options.customImgSize + 'px !important }\n' +
1262 '.WB_feed_v3 .WB_feed_repeat ul.WB_media_a > li.WB_pic > img { width: ' + $options.customImgSize + 'px !important; height: ' + $options.customImgSize + 'px !important }\n';
1263 }
1264 if (Number($options.customTotalWidth) > 0) {
1265 cssText += '.WB_feed_v3 ul.WB_media_a[node-type="fl_pic_list"] { width: ' + $options.customTotalWidth + 'px !important }\n';
1266 }
1267 if (Number($options.customVideoSize) > 0) {
1268 cssText += '.WB_feed_v3 ul.WB_media_a > li.WB_video .WB_h5video { width: ' + $options.customVideoSize + 'px; height: ' + Math.round(Number($options.customVideoSize)*0.564) + 'px }\n' +
1269 '.WB_feed_v3 ul.WB_media_a > li.WB_video .WB_h5video video { width: 100% !important; height: 100% !important }\n';
1270 }
1271 cssText += '.WB_feed_v3 .WB_feed_spec_b .spec_box > .WB_feed_spec_pic, .WB_feed_v3 .WB_feed_spec_c .spec_box > .WB_feed_spec_pic { display: inline-block; width: 150px; height: 90px }\n' +
1272 '.WB_feed_v3 .WB_feed_spec_c .WB_feed_spec_pic > .WB_feed_spec_clearfix, .WB_feed_v3 .WB_feed_spec_c .WB_feed_spec_pic > .W_icon_tag_artical { display: none }\n' +
1273 '.WB_feed_v3 .WB_feed_spec_b .spec_box > .WB_feed_spec_pic img, .WB_feed_v3 .WB_feed_spec_c .spec_box > .WB_feed_spec_pic img { width: 150px; min-height: initial }\n' +
1274 '.WB_feed_v3 .WB_feed_spec_b .spec_box > .WB_feed_spec_pic + .WB_feed_spec_info, .WB_feed_v3 .WB_feed_spec_c .spec_box > .WB_feed_spec_info { display: inline-block; vertical-align: middle; width: 310px }\n' +
1275 '.WB_feed_v3 .WB_feed_spec_b .spec_box > .WB_feed_spec_info .WB_feed_spec_tit, .WB_feed_v3 .WB_feed_spec_c .spec_box > .WB_feed_spec_info .WB_feed_spec_tit { font-size: 16px; margin-bottom: 0px }\n' +
1276 '.WB_feed_v3 .WB_feed_spec_b .spec_box > .WB_feed_spec_info { font-size: 12px }\n';
1277 }
1278 if ($options.useCustomStyles) {
1279 cssText += $options.customStyles;
1280 }
1281 styles.innerHTML = cssText + '\n';
1282 };
1283 // 在用户信息气球或用户主页上添加屏蔽链接
1284 var showUserFilterBtn = function (node) {
1285 if (!node) { node = document.body; }
1286 var balloon = (node.classList.contains('layer_personcard') || node.querySelector('.layer_personcard')), userData, toolbar, uid;
1287 if (balloon) {
1288 // 获得关注链接
1289 userData = node.querySelector('.name a[uid]');
1290 if (!userData || node.querySelector('#wbpUserFilter')) { return false; }
1291 uid = userData.getAttribute('uid');
1292 toolbar = node.querySelector('.c_btnbox');
1293 } else if ($.scope() === 2) {
1294 if (userData = $('wbpUserFilter')) {
1295 // 按钮已存在时只更新状态
1296 userData.update();
1297 return false;
1298 }
1299 uid = $.oid;
1300 toolbar = node.querySelector('.pf_opt .opt_box');
1301 }
1302 if (!toolbar || uid === $.uid) { return false; }
1303 // 创建分隔符
1304 var button = document.createElement('div');
1305 if (balloon) {
1306 button.style.display = 'inline-block';
1307 } else {
1308 button.className = 'btn_bed W_fl';
1309 }
1310 button.id = 'wbpUserFilter';
1311 // 创建操作链接
1312 var link = document.createElement('a');
1313 button.appendChild(link);
1314 link.href = 'javascript:void(0)';
1315 (button.update = function () {
1316 link.className = balloon ? 'W_btn_b' : 'W_btn_d btn_34px';
1317 if ($options.userBlacklist.indexOf(uid) === -1) {
1318 link.innerHTML = '<span>屏蔽</span>';
1319 } else {
1320 link.innerHTML = '<span><em class="W_ficon ficon_right">Y</em>已屏蔽</span>';
1321 }
1322 })();
1323 $.click(link, function () {
1324 // 切换屏蔽状态
1325 var i = $options.userBlacklist.indexOf(uid);
1326 if (i === -1) {
1327 $options.userBlacklist.push(uid);
1328 } else {
1329 $options.userBlacklist.splice(i, 1);
1330 }
1331 $options.save();
1332 $filter();
1333 if (balloon) {
1334 // 回溯到顶层,关闭信息气球
1335 while (!node.classList.contains('W_layer')) {
1336 node = node.parentNode;
1337 }
1338 $.remove(node);
1339 //node.style.display = 'none';
1340 }
1341 if (i = $('wbpUserFilter')) { i.update(); }
1342 });
1343 toolbar.insertBefore(button, toolbar.querySelector('div+div'));
1344 };
1345 // 根据当前设置修改页面
1346 var apply = function (init) {
1347 // 极简阅读模式
1348 toggleReaderMode();
1349 // 设置链接
1350 showSettingsBtn();
1351 // 屏蔽用户按钮
1352 showUserFilterBtn();
1353 // 屏蔽版面模块
1354 hideModules();
1355 // 清除发布框中的默认话题
1356 clearDefTopic();
1357 // 人工添加首页消息导航栏
1358 addMessageNav();
1359 // 覆盖当前模板设置
1360 overrideSkin();
1361 // 应用自定义CSS
1362 customStyles();
1363 // 禁止默认发布新微博到当前浏览的分组
1364 disableDefaultGroupPub(document);
1365 // 展开字数超长微博
1366 expandLongFeeds(document);
1367 // 将微博来源移动至底部
1368 moveSourceToBottom(document);
1369 // 禁止弹出“有新的热门微博”等提示
1370 noHotYellowTags();
1371 // 首次进入用户主页时显示全部微博
1372 if (init) {
1373 redirectToAllFeeds();
1374 }
1375 };
1376
1377 // IFRAME载入不会影响head中的CSS,只添加一次即可
1378 var myStyles = document.createElement('style');
1379 myStyles.type = 'text/css';
1380 myStyles.id = 'wbpDialogStyles';
1381 myStyles.innerHTML = '.wbpTip{border:1px solid;display:block;line-height:23px;text-align:center}.wbpTip:hover{background-color:#D0FFD0;border-color:#40D040;color:#40D040;margin-bottom:10px}.wbpTip:not(:hover)~:not(.wbpTipLine){display:none !important}.wbpTip:hover~*{opacity:0.5}.wbpTip:hover+.wbpTipLine{display:none}.wbpTipLine{padding-bottom:20px;border-bottom-style:solid;border-bottom-width:1px}#wbpNavBar{margin-bottom:20px}#wbpNavBar .lev a,#wbpNavBar .lev2 a,#wbpNavBar .levmenu,#wbpNavBar .levmenu .lm_li:hover{background-image:none}#wbpNavBar .lev a.lev_curr{background-color:transparent}#wbpNavBar .left_nav_line fieldset .btns{margin-left:148px}#wbpNavBar .WB_left_nav .lev_edit .lev a{width:200px}.wbpSettings p{line-height:150%}.wbpSettings p+p{margin-top:10px}.wbpSettings .W_vline{margin:0 8px}.wbpSettings table{line-height:30px;margin-top:8px}.wbpSettings span.link{position:relative}.wbpSettings span.link a>span{display:none}.wbpSettings span.link a>span li{list-style:circle inside;padding-left:1em;text-indent:-1em}.wbpSettings span.link a>span li+li{margin-top:5px}.wbpSettings span.link a>span p+p{margin-top:10px}.wbpSettings span.link a:hover>span{display:block;position:absolute;margin-top:10px;margin-left:-100px;width:250px;padding:5px;z-index:20000;background:#FFFFB0;color:black;border:1px solid #808000;text-align:left;text-decoration:none;border-radius:3px 3px;box-shadow:3px 3px 3px rgba(0,0,0,0.2)}.wbpTabHeaders{float:left;width:100px;margin-right:10px}.wbpTabHeaders a{display:block;padding:6px 0;text-align:center;text-decoration:none}.wbpTabHeaders a:hover{background-color:#C6E8F4}.wbpTabHeaders a.current{background-color:#79C5E9;color:white;cursor:default}.wbpInput{border:1px solid #D2D5D8;padding:0 2px}.wbpInlineInput{display:inline-block;width:30px;margin:0 3px;vertical-align:middle}.wbpInput input{width:100%;height:22px;border:0;padding:0;margin:0;display:block}.wbpSettings>div{margin-top:15px}.wbpSettings textarea{width:440px;margin-top:10px;border:1px solid #D2D5D8}.wbpSettings input[type="checkbox"],.wbpSettings input[type="radio"]{vertical-align:middle;margin-right:5px}.wbpTabModules tr.wbpRowSpacing td{padding-top:10px}.wbpTabModules a>.W_icon{display:inline-block !important}.wbpTabModules a>.W_icon_EURO{display:inline-block !important}.wbpKeywordBlock{margin-top:10px;border:1px solid #D2D5D8;padding:8px 8px 0}.wbpKeywordBlock em{font-weight:bold;margin-right:15px}.wbpToolBtns{width:135px;text-align:right}.wbpToolBtns a+a{margin-left:5px}.wbpListWrapper{margin:8px 0;max-height:120px;overflow:hidden}.wbpListWrapper:hover{overflow-y:auto}.wbpKeywordsList{margin-top:-5px;line-height:18px}.wbpKeywordsList a{margin:5px 5px 0 0;padding:0 4px;border:1px solid;display:inline-block;height:18px;white-space:nowrap}.wbpKeywordsList a:hover{text-decoration:none}.wbpWhiteKeywordsList a{border-color:#008000;color:#008000}.wbpWhiteKeywordsList a.regex{background-color:#80FF80}.wbpWhiteKeywordsList a:hover{border-color:#008000;background-color:#D0FFD0}.wbpBlackKeywordsList a{border-color:#D00000;color:#D00000}.wbpBlackKeywordsList a.regex{background-color:#FFB0B0}.wbpBlackKeywordsList a:hover{border-color:#FF0000;background-color:#FFD0D0}.wbpGrayKeywordsList a{border-color:#808000;color:#808000}.wbpGrayKeywordsList a.regex{background-color:#FFFF00}.wbpGrayKeywordsList a:hover{border-color:#808000;background-color:#FFFFB0}.wbpUserList>a{margin:5px 5px 0 0;padding:3px;border:1px solid;display:inline-block;cursor:pointer;text-align:center;text-decoration:none}';
1382 document.head.appendChild(myStyles);
1383 // 为右边栏动态模块打屏蔽标记
1384 tagRightbarMods($('v6_pl_rightmod_recominfo'));
1385 // 处理动态载入内容
1386 document.addEventListener('DOMNodeInserted', function (event) {
1387 var scope = $.scope(), node = event.target;
1388 // if (node.tagName !== 'SCRIPT') { console.log(node); }
1389 if (scope && node.tagName === 'UL' && node.parentNode.getAttribute('node-type') === 'accountLayer') {
1390 // 重新载入设置按钮
1391 showSettingsBtn(node);
1392 }
1393 if (node.tagName === 'UL' && node.parentNode.classList.contains('gn_topmenulist_tips')) {
1394 // 禁止弹出“有新的热门微博”等提示
1395 noHotYellowTags(node);
1396 }
1397 if (node.tagName !== 'DIV') { return; }
1398 if (node.classList.contains('W_layer')) {
1399 // 显示未关注作者的长微博全文
1400 showAllArticleText(node.firstChild);
1401 }
1402 if (node.classList.contains('WB_feed_type') || node.classList.contains('WB_feed') || node.querySelector('.WB_feed')) {
1403 // 展开字数超长微博
1404 expandLongFeeds(node);
1405 // 将微博来源移动至底部
1406 moveSourceToBottom(node);
1407 }
1408 if (node.classList.contains('layer_personcard') || node.querySelector('.layer_personcard')) {
1409 // 在用户信息气球或个人主页信息栏中显示屏蔽按钮
1410 showUserFilterBtn(node);
1411 } else if (node.classList.contains('WB_left_nav')) {
1412 // V6版需要人工添加消息导航栏
1413 addMessageNav();
1414 } else if (node.classList.contains('send_weibo')) {
1415 // 禁止默认发布新微博到当前浏览的分组
1416 disableDefaultGroupPub(node);
1417 // 清除发布框中的默认话题
1418 clearDefTopic();
1419 } else if (node.classList.contains('WB_cardwrap')) {
1420 // 微博新首页右边栏模块处理
1421 tagRightbarMods(node.parentNode);
1422 }
1423 }, false);
1424 // 检测按键,开关极简阅读模式
1425 document.addEventListener('keyup', function onKeyPress(event) {
1426 if ($dialog.shown()) { return; }
1427 var scope = $.scope();
1428 if (scope && event.keyCode === 119) {
1429 if (scope === 1) {
1430 $options.readerModeIndex = !$options.readerModeIndex;
1431 } else {
1432 $options.readerModeProfile = !$options.readerModeProfile;
1433 }
1434 $options.save();
1435 toggleReaderMode();
1436 }
1437 }, false);
1438
1439 apply.modules = modules;
1440 return apply;
1441})();
1442
1443// 先读取本地设置
1444$.get($.uid.toString(), undefined, function (options) {
1445 var init = function () {
1446 // 如果第一次运行时就在作用范围内,则直接屏蔽关键词(此时页面已载入完成);
1447 // 否则交由$filter中注册的DOMNodeInserted事件处理
1448 if ($.scope()) { $filter(); }
1449 // 直接应用页面设置(此时页面已载入完成)
1450 // 与IFRAME相关的处理由$page中注册的DOMNodeInserted事件完成
1451 $page(true);
1452 };
1453 if (!$options.load(options)) {
1454 console.warn('“眼不见心不烦”设置读取失败!\n设置信息格式有问题。');
1455 } else if (options && $options.version < $.version) {
1456 $options.save(true); // 更新版本信息
1457 if ($options.updateNotify) {
1458 alert('您已更新到“眼不见心不烦”v2.6.1:\n\n- ' + '修正直接查看大图功能失效的问题;修正紧凑版式下部分内容显示错位的问题'.split(';').join('\n- '));
1459 }
1460 }
1461 init();
1462});
1463});