Forked from hirogasa/NicovideoPlayingFavicon.user.js
Last active
January 12, 2017 15:34
-
-
Save vzvu3k6k/6162695 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name NicovideoPlayingFavicon | |
// @namespace https://twitter.com/hirogasa/ | |
// @match http://www.nicovideo.jp/watch/* | |
// @description ニコニコ動画の再生中ページのFaviconを変更します。 | |
// @version 1.4 | |
// @grant none | |
// ==/UserScript== | |
if(window.WatchApp) { // Flashプレーヤー | |
let pac = WatchApp.ns.init.PlayerInitializer.playerAreaConnector; | |
pac.addEventListener("onVideoPlayed", setPlayingFavicon); | |
pac.addEventListener("onVideoStopped", setDefaultFavicon); | |
pac.addEventListener("onVideoEnded", setDefaultFavicon); | |
} | |
// ZenzaWatchをインストールした状態で | |
// Flashプレーヤーのみに対応している動画を開いた場合、 | |
// WatchAppとZenzaWatchの両方が定義される。 | |
if(window.WatchJsApi || // 公式のHTML5プレーヤー | |
window.ZenzaWatch) { // ZenzaWatch | |
let video = document.querySelector("video"); | |
video.addEventListener("playing", setPlayingFavicon); | |
video.addEventListener("pause", setDefaultFavicon); | |
// 公式のHTML5プレーヤーは再生終了時にpauseとendedが発火するが、 | |
// ZenzaWatchはendedのみが発火する。 | |
video.addEventListener("ended", setDefaultFavicon); | |
} | |
function setPlayingFavicon(){ | |
changeFavicon("http://i.imgur.com/JYOD7ss.png"); | |
} | |
function setDefaultFavicon(){ | |
changeFavicon("http://res.nimg.jp/img/favicon.ico"); | |
} | |
function changeFavicon(url){ | |
let links = document.querySelectorAll("link[rel='shortcut icon']"); | |
for(let link of links) { | |
link.remove(); | |
} | |
let newLink = document.createElement("link"); | |
newLink.rel = "shortcut icon"; | |
newLink.href = url; | |
document.head.appendChild(newLink); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment