阅读:3479回复:5
[求助]改写greasemonkey的user.js脚本。已解决。(另有adblockplus替代方法。)
一个greasemonkey的user.js脚本,用于选择性的移除sina news ads,想做个性化改动
原脚本:deleteall("//*[@name='PublicRelation']"); 改为deleteall("//div[@id='PublicRelation5']"); 可选择性去除PublicRelation5......选择性保留的PublicRelation4等。 实例: http://finance.sina.com.cn/roll/2005111 ... 7829.shtml 另附原脚本: // // Copyright (c) 2005, wwr // // -------------------------------------------------------------------- // // This is a Greasemonkey user script. // // To install, you need Greasemonkey: http://greasemonkey.mozdev.org/ // Then restart Firefox and revisit this script. // Under Tools, there will be a new menu item to "Install User Script". // Accept the default configuration and install. // // To uninstall, go to Tools/Manage User Scripts, // select "Sina News Ad Remover", and click Uninstall. // // -------------------------------------------------------------------- // // ==UserScript== // @name Sina News Ad Remover // @namespace http://gnor.net/ // @description Removes the box ads in the news page and cleans up the start page of news.sina.com.cn. // @include http://*.sina.com.cn/* // @version 0.0.6 // ==/UserScript== (function() { if (!document.location.href.match('.shtml')) { // delete top tables deleteall("//BODY/CENTER/comment()[contains(string(), 'Sina_News_Head_End')]/preceding-sibling::TABLE"); //delete banners between columns //deleteall("//EMBED[contains(@src, 'ad4.sina')]/ancestor::TABLE[1]"); deleteall("//OBJECT[contains(@codebase, 'download.macromedia.com')]"); deleteall("//IFRAME[contains(@src, 'adsina')]/ancestor::TABLE[1]"); deleteall("//A[contains(@href, 'http://ad.cn')]"); //delete marqueen ad deleteall("//IFRAME[contains(@src, 'iframe/ad/marqueen')]//parent::TD"); }else{ //clean up news item page deleteall("//*[@name='PublicRelation']"); //delete right side bar deleteme( document.getElementById( 'toolBar' )); //delete top bar deleteme( getObject( document, "//CENTER/TABLE[1]")); deleteme( getObject( document, "//DIV[@id='outer']/TABLE[1]/TBODY/TR[1]/TD[3]")); //delete iask bar //deleteme( getObject( document, "//FORM[contains(@action, 'iask.com')][3]/ancestor::TABLE[1]")); } function deleteme( obj) { try { obj.parentNode.removeChild( obj); } catch( e) {GM_log("failed delete object");} } function deleteall(xpath) { try { var matches = document.evaluate(xpath, document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); var d = new Array(); for (i = 0; i <= matches.snapshotLength; i++ ) { thisMatch = matches.snapshotItem(i); thisMatch.style.display = 'none'; } } catch (e) {} } function getObject( obj, xpath) { try { val = document.evaluate( xpath, obj, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } catch( e) {} if (!val) {GM_log("cannot find " + xpath); } return val; } } )(); |
|
|
1楼#
发布于:2005-11-15 13:17
|
|
2楼#
发布于:2005-11-15 13:17
谢先!!!
试过,移除PublicRelation失效,不想留下的也会显示出。 |
|
|
3楼#
发布于:2005-11-15 13:17
一个替代方法:
用adblock plus: /\.sina\..+(PublicRelation(?!4)|sinatail)/ greasemonkey的user.js脚本去除: deleteall("//*[@name='PublicRelation']"); 这一行. 倒是也可以实现意图 |
|
|
4楼#
发布于:2005-11-15 13:17
Re: [求助]改写一行greasemonkey的user.js脚本。谢先!!!(有个adblockplus替代�...
一个greasemonkey的user.js脚本,用于选择性的移除sina news ads,想做个性化改动,无奈不懂js: //*[@id='PublicRelation1'] //*[@id='PublicRelation2'] //*[@id='PublicRelation3'] //*[@id='PublicRelation5'] 是不是這樣? 沒試過~ |
|
5楼#
发布于:2005-11-15 13:17
|
|
|