Skip navigation.

ノヴム・オペラヌム

DiggにDuggMirrorへのリンクを追加するユーザーJavaScript

先日、DiggからDuggMirrorに移動するブックマークレットを作ったんですが、やっぱりいちいちブックマークレットを使うのは面倒なのでユーザーJavaScriptにしました。

車輪のなんちゃらっぽいけど気にしない。

// ==UserScript==
// @name digg.com - Append DuggMirror anchors
// @author Satoru Watanabe
// @namespace http://my.opera.com/Watanabe/
// @version 1.0.1
// @include http://digg.com/*
// @include http://www.digg.com/*
// ==/UserScript==

/*
 * Copyright (c) 2007 Satoru Watanabe
 * This script is licensed under the MIT license.
 */

(function () {
  var sources = document.evaluate('//div[@class="news-summary"]//h3', document, null,
                                  XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
  var topics = document.evaluate('//li[@class="digg-count"]//a/@href', document, null,
                                 XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

  if (sources.snapshotLength == 0) {
    var mirror = createMirrorAnchor(location.href.replace(/^http:\/\/.*?(\/.*)/,'$1'));
    var source = document.evaluate('//div[@class="news-body"]//h3', document, null,
                                   XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;

    source.appendChild(mirror);
  } else {
    for (var i = 0, len = topics.snapshotLength; i < len; i++) {
      var mirror = createMirrorAnchor(topics.snapshotItem(i).nodeValue.replace(/^http:\/\/.*?\/(.*)/,'$1'));

      sources.snapshotItem(i).appendChild(mirror);
    }
  }

  function createMirrorAnchor(uri) {
    var result = document.createElement('a');

    result.href = 'http://duggmirror.com' + uri;
    result.style.marginLeft = '0.3em';

    var text = document.createTextNode('[Dugg]');

    result.appendChild(text);

    return result;
  }
}) ();

digg-dugg.user.js

追記: 2007-02-21T12:08:52+09:00

Greasemonkeyで動くように修正。

ブックマークレット 02OperaにXSS脆弱性

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies