ã¯ã¦ããæ£è¦è¡¨ç¾ãXPathã§ãã£ã«ã¿ã§ããGreasemonkey
å æ id:solailoãããã
id:solailo ããããªãã¥ã¼ã¢ã«ã«å¯¾å¿ããã¦ããããã§ãã¾ããï¼
http://d.hatena.ne.jp/rikuo/20080902#c1229345579
ã¨ã³ã¡ã³ããããã ãã¾ãããããããã¨ããã®ã¯ä»¥åã«ã¯ã¦ãªå¿åãã¤ã¢ãªã¼ã§æ稿ããããã® Greasemonkey ã®ãã¨
はてブのhotentryで、2chコピペブログや「ネタ」を削除するGreasemonkeyを勝手に改造 - はてな匿名ダイアリー
ãã¡ãã¯ãã¯ã¦ãªããã¯ãã¼ã¯ã®æ³¨ç®ã»äººæ°ã¨ã³ããªã¼ãæ£è¦è¡¨ç¾ã¨XPathã§ãã£ã«ã¿ã§ããæ©è½ããã£ãã®ã§ãããæ¨å¹´11æã«è¡ããããªãã¥ã¼ã¢ã«ã§ãã¼ã¸æ§é ã大ããå¤ãããåããªããªã£ã¦ãã¾ããã
ã¨ããããã§ãä»åã¯ããããªãã¥ã¼ã¢ã«ã«å¯¾å¿ããã§ãã£ã¦ããã¤ãæ©è½è¿½å ãããã¨ã«ããããã§ãã
id:solailoããã«ã³ã¡ã³ãããã ãã¦ãããå®ã«1ã¶æ以ä¸ããã£ã¦ãã¿ã¾ãã*1ã
ã¤ã³ã¹ãã¼ã«ã¯ãã¡ããã
http://userscripts.org/scripts/show/40632
ãã®Greasemonkeyã®æ¦ç¥
ã¯ã¦ãªããã¯ãã¼ã¯ã®æ³¨ç®ã¨ã³ããªã¼ã人æ°ã¨ã³ããªã¼ãã¾ãåã¦ã¼ã¶ã¼ã®ãæ°ã«å ¥ãã®ãã¼ã¸ã§æ£è¦è¡¨ç¾ãXPathã§ãã£ã«ã¿ãã¾ã*2ã
使ãæ¹
æ£è¦è¡¨ç¾ã®å ´å
注ç®ã»äººæ°ã¨ã³ããªã¼ã§ã¯ãã®ãããªè¡¨ç¤ºã«ãªã£ã¦ãããã¨æãã¾ãã
ãã®Gresemonkeyã§ä¸»ã«ãã£ã«ã¿ã®å¯¾è±¡ã¨ãªãã®ã¯ã4ç¹
- ã¨ã³ããªã¼ã®ã¿ã¤ãã«ã®æåå
- ã¿ã°
- æ¦è¦ï¼â»è¡¨ç¤ºãã¦ããã°ï¼
- ã¨ã³ããªã¼ã®URL
ãã¡ãã«ãªãã¾ãã
注ç®ã»äººæ°ã¨ã³ããªã¼ã§ã¯ã¿ã¤ãã«ã®æååã64ãã¤ãã§çç¥ããã¦ãã¾ãã¾ããããã£ã«ã¿ã¯çç¥åã®ã¿ã¤ãã«ã対象ã¨ãã¦ãã¾ããã¿ã°ã«ã¤ãã¦ã¯ãã¨ã³ããªã¼ã«ä»ãããã¦ããã¿ã°ãå
¨ã¦åå¾ã¯ã§ããã注ç®ã»äººæ°ã¨ã³ããªã¼ã®ãã¼ã¸ã«è¡¨ç¤ºããã¦ãããã®ã®ã¿ãã対象ã«ãªãã¾ããæ¦è¦ã«ã¤ãã¦ã¯è¡¨ç¤ºã»é表示ãåãæãããã¾ãã®ã§ãé表示ã®å ´åã¯é©ç¨ããã¾ããã
è¨å®ã®ä»æ¹ã¯ãããã
// ã¿ã¤ãã«ã®æååã«ã¤ãã¦ã®è¨å® filters.title = [ ]; // ã¿ã°ã«ã¤ãã¦ã®è¨å® filters.tag = [ ]; // æ¦è¦é¨åã«ã¤ãã¦ã®è¨å® filters.summary = [ ]; // URLã«ã¤ãã¦ã®è¨å® url = [ ];
ã¨ãªãã¾ãã
ã¾ããã¿ã¤ãã«ã»ã¿ã°ã»æ¦è¦ã«ã©ãã1ã¤åè´ããã°ãªãã±ã¼ãã¨ããã¾ã¨ãè¨å®ãã§ãã¾ã
filters.all = [ ];
ãã ããã§ããã°åå¥ã«æå®ããæ¹ããåä½ã軽快ã«ãªãã¾ãã
æ¸ãæ¹
æ£è¦è¡¨ç¾ã使ããã¨ãã§ãã¾ã
filters.tag = [ /ããã¯(ã²ã©ã|ããã)/, /ãã¿|neta/i, ]; url = [ /http:\/\/(foo|bar|baz).com/, ];
ãªã©ã
æ£è¦è¡¨ç¾ãåãããªããã¨ããæ¹ã¯
filters.tag = [ 'ããã¯ã²ã©ã', 'ããã¯ããã', 'ãã¿', 'neta', ]; url = [ 'http://foo.com/', 'http://bar.com/', 'http://baz.com/', ];
ã¨æ¸ãã¦ããªãã±ã¼ã§ãã
ãæ°ã«å ¥ããã¼ã¸ã®å ´å
- b.hatena.ne.jp/userID/favorite
- b.hatena.ne.jp/userID/group
- b.hatena.ne.jp/userID/starfriends
ã§ãåãããã«ä½¿ããã®ã§ããããã£ã«ã¿ã®å¯¾è±¡ãè¥å¹²ç°ãªãã¾ãã
ã¿ã°ã¯ãæ°ã«å
¥ãã»ã°ã«ã¼ãã¡ã³ãã¼ã»ã¹ã¿ã¼ãã¬ã³ããåã³èªåã®ãããããã¤ããã¿ã°ã対象ã«ãªãã¾ãããæ¦è¦ã¯è¡¨ç¤ºãããªãã®ã§å¯¾è±¡å¤ãã¨ãªãã¾ãã
XPathã®æå®
ä¸è¨ã®æ£è¦è¡¨ç¾ãªã©ä»¥å¤ã«ãä¸ç´è åãã®è¨å®ã¨ã㦠XPath ã§ã®æå®ãã§ãã¾ãã
// 注ç®ã»äººæ°ã¨ã³ããªã¼ç¨ xpath.hotentry = [ ]; // ãæ°ã«å ¥ããã¼ã¸ç¨ xpath.favorite = [ ];
ãã¼ã¸æ§é ãç°ãªãããã注ç®ã»äººæ°ã¨ã³ããªã¼ç¨ã¨ãæ°ã«å ¥ãä»ã¦ã¼ã¶ã¼ãã¼ã¸ç¨ã®ãã®ã¨åãã¦è¨å®ããå¿ è¦ãããã¾ãããä¾ãã°
// 注ç®ã»äººæ°ã¨ã³ããªã¼ç¨ xpath.hotentry = [ // ã«ãã´ãªã¼ããã³ã³ãã¥ã¼ã¿ã»ITãã®å ´å 'descendant::li[@class="category"]/a[starts-with(@href,"/hotentry/it")]', // ã¿ã°ãfooããä»ãã¦ãã¦ãä¸ã¤ã¿ã°ãbarããã¤ãã¦ããå ´å 'descendant::li[@class="tags" and child::a[contains(text(),"foo")] and child::a[contains(text(),"bar")]]', // (id:sampleããæ°ã«å ¥ãã«ç»é²ãã¦ãã¦)id:sampleãããã¯ãã¼ã¯ãã¦ããå ´å 'descendant::li[@class="favorite"]/img[contains(@title,"sample")]', ];
ãªã©ãè¤éãªæ¡ä»¶ãè¨å®ãã¦é¸å¥ãããã¨ãã§ãã¾ãã
XPath ã¯ã©ãæ¸ãã°ããã®ï¼ã¨ããããããXPath ã£ã¦ãªã«ï¼ã¨ããã®ã¯èª¬æãããã¼é¢åãªã®ã§ãå²æãã¾ãããããããã¨ãã§ããããã¨ãããã¨ã§ã
ãã£ã«ã¿ã«å¯¾ãã¦ã®å¦ç
åè¿°ã®è¨å®ã«åè´ããã¨ã³ããªã¼ã«ã¤ãã¦ãè¡ãå¦çã¯3種é¡ããã¾ã
é表示
æåéã表示ããªã
å¸èå
æµããããããã«ãã£ããã¨
強調
ãããéã«ç®ç«ã¤ããã«
ãã®ãããªå¦çã«ãªãã¾ãã
åãæãã¯ä¸é¨ãããã«ãã¿ã³ã追å ãã¦ããã®ã§ããããã¯ãªãã¯ãã¦ä¸ããã
æ°åã¯ãã£ã«ã¿ãé©ç¨ãã¦ããã¨ã³ããªã¼ã®æ°ã§ãã
ãã®Greasemonkeyã®çã
å
ã«ãªã£ãGreasemonkeyã¯ããã£ã«ã¿ã®æ¡ä»¶ã«åè´ãããæ¶ããã¨ããåä½ã§ãããããããç¹å®ã®æ¡ä»¶ã«åã£ãã強調ãã¦è¡¨ç¤ºãã¦ãããããããªããï¼ã¨èãã¾ããã
æ°ã«ãªãã¿ã°ãè¨å®ããããæ°ã«ãªãã¯ã¼ããè¨å®ããããããã¨ã§ããããç®åºãã¦ä½¿ãæ¹åãããããªã¼ãã£ã¦ããã
ãã¨ã¡ãªã¿ã«ãã¯ã¦ãªããã¯ãã¼ã¯ã®AutoPagerizeã«ã対å¿ãã¦ãã¾ãã
[ã©ãããå©ç¨ä¸ããã]
ä¼¼ããããªGreasemonkey
*1:1ã¶æããã£ãã¨ããããã¯ãæ£æä¼ã¿ã«ãã£ã¦ãã¾ãããã¨æã£ã¦ããçµå±ã飲ã¿ä¼ããã£ããç®±æ ¹é§ ä¼è¦ã¦ããã§ãã©ãã©éãããæ¾ã®å ãæãã¦ããããããçæãã¦ã¾ããâ¦â¦ãã¹ããã»ã³
*2:èªåãããã¯ãã¼ã¯ãããã®ï¼èªåã®ãã¼ã¸ï¼ã§ã¯ãã£ã«ã¿ã®å¿ è¦æ§ã¯ãªãã§ããããããè¡ãã¾ãã