copy url or feed url of current page
http://keysnail.g.hatena.ne.jp/mooz/20100619/1276943161
これを使っていたのだけれど、うまく動かないことがたまにあった。
原因は、
href属性のURIが「/」から始まっているんだから、これはサイトルート相対パス(またはコンテキスト相対パス)と言われるやつでサイトルートである「http://www.google.com/」からの相対パスでなければなりません。
http://itmst.blog71.fc2.com/blog-entry-140.html
にあるような、"/"で始まるパスをうまく扱ってくれないことだった。
ので、直した。
ついでに、ページ自体のurlもコピーできるようにした。
///////////////////////////////////////// // copy url ext.add("copy-url", function () { const doc = content.document; let feeds = [[e.getAttribute("title"), e.getAttribute("href")] for ([, e] in Iterator(doc.querySelectorAll(['link[type="application/rss+xml"]', 'link[type="application/atom+xml"]'])))]; var uh = window.content.location.href.replace(/(.*?\/\/[^/]*)(\/.*)?/,"$1"); for (i = 0; i < feeds.length; i++) if ( feeds[i][1].substr(0,1) == "/" ) feeds[i][1] = uh + feeds[i][1]; feeds.unshift([window.content.document.title,window.content.location.href]); prompt.selector( { message : "Select url to copy:", collection : feeds, callback : function (i) { if (i >= 0) command.setClipboardText(feeds[i][1]); } } ); }, "Copy url or feed url of current page");