焦油含量中
火狐狸
火狐狸
  • UID97
  • 注册日期2004-11-24
  • 最后登录2011-12-18
  • 发帖数192
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
阅读:2996回复:5

[求助]改写greasemonkey的user.js脚本。已解决。(另有adblockplus替代方法。)

楼主#
更多 发布于:2005-11-15 13:17
一个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;
  }
}
)();
FireFox重在体验!时间是体验的基础!
fiag
管理员
管理员
  • UID1188
  • 注册日期2004-12-21
  • 最后登录2024-04-22
  • 发帖数4681
  • 经验686枚
  • 威望0点
  • 贡献值402点
  • 好评度51点
1楼#
发布于:2005-11-15 13:17
Re: [求助]改写一行greasemonkey的user.js脚本。谢先!!!
焦油含量中:一个greasemonkey的user.js脚本,用于选择性的移除sina news ads,想做个性化改动,无奈不懂js:

原脚本:deleteall("//*[@name='PublicRelation']");

回到原帖


//*[@name='PublicRelation1']
//*[@name='PublicRelation2']
//*[@name='PublicRelation3']
//*[@name='PublicRelation5']

??
焦油含量中
火狐狸
火狐狸
  • UID97
  • 注册日期2004-11-24
  • 最后登录2011-12-18
  • 发帖数192
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
2楼#
发布于:2005-11-15 13:17
谢先!!!
试过,移除PublicRelation失效,不想留下的也会显示出。
FireFox重在体验!时间是体验的基础!
焦油含量中
火狐狸
火狐狸
  • UID97
  • 注册日期2004-11-24
  • 最后登录2011-12-18
  • 发帖数192
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
3楼#
发布于:2005-11-15 13:17
一个替代方法:

用adblock plus:
/\.sina\..+(PublicRelation(?!4)|sinatail)/

greasemonkey的user.js脚本去除:
deleteall("//*[@name='PublicRelation']");
这一行.

倒是也可以实现意图
FireFox重在体验!时间是体验的基础!
djshow
小狐狸
小狐狸
  • UID8986
  • 注册日期2005-09-30
  • 最后登录2006-02-28
  • 发帖数2
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
4楼#
发布于:2005-11-15 13:17
Re: [求助]改写一行greasemonkey的user.js脚本。谢先!!!(有个adblockplus替代�...
一个greasemonkey的user.js脚本,用于选择性的移除sina news ads,想做个性化改动,无奈不懂js:

原脚本:deleteall("//*[@name='PublicRelation']");


//*[@id='PublicRelation1']
//*[@id='PublicRelation2']
//*[@id='PublicRelation3']
//*[@id='PublicRelation5']

是不是這樣? 沒試過~
焦油含量中
火狐狸
火狐狸
  • UID97
  • 注册日期2004-11-24
  • 最后登录2011-12-18
  • 发帖数192
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度0点
5楼#
发布于:2005-11-15 13:17
Re: [求助]改写一行greasemonkey的user.js脚本。谢先!!!(有个adblockplus替代�...
djshow

//*[@id='PublicRelation1']
//*[@id='PublicRelation2']
//*[@id='PublicRelation3']
//*[@id='PublicRelation5']

是不是這樣? 沒試過~
回到原帖


谢谢!

对PublicRelation移除失效了
FireFox重在体验!时间是体验的基础!
游客

返回顶部