Skip to content

Instantly share code, notes, and snippets.

@nobodyplace
Created October 2, 2011 03:58
Show Gist options
  • Save nobodyplace/1257023 to your computer and use it in GitHub Desktop.
Save nobodyplace/1257023 to your computer and use it in GitHub Desktop.
ニコニコ動画のcanonicalを置き換えるGreasemonkey
// ==UserScript==
// @name Nico Canonical
// @version 0.0.1
// @namespace https://gist.github.com/1257023
// @description ニコニコ動画のcanonicalを置き換えるGreasemonkey
// @include http://www.nicovideo.jp/watch/*
// @updated 2011/10/02 12:56:00
// ==/UserScript==
// 0.0.1 - 2011/10/02 リリース
(function(doc){
'use strict';
var w = unsafeWindow; //ページ内要素にアクセスするためunsafeWindowを使用する
var id = w.Video['id']; //動画ID
var links = doc.getElementsByTagName('head')[0].getElementsByTagName('link');
for (var i=0; i<links.length; i++) {
if (links[i].getAttribute('rel').toLowerCase() == 'canonical') {
links[i].href = '/watch/' + id;
break;
}
}
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment