Skip to content

Instantly share code, notes, and snippets.

@piouc
Created April 22, 2017 17:58
Show Gist options
  • Save piouc/735384bc067647dce94147912b60e2a0 to your computer and use it in GitHub Desktop.
Save piouc/735384bc067647dce94147912b60e2a0 to your computer and use it in GitHub Desktop.
nicovideo fake premium
// ==UserScript==
// @name nicovideo fake premium
// @namespace org.kamisama.nicovideo-fake-premium
// @include http://www.nicovideo.jp/watch/sm*
// @version 1
// @grant none
// @run-at document-start
// ==/UserScript==
/*
// watch_app.jsの実行を一度停止し再度追加することによって、下のイベントリスナの優先順位をあげる
*/
document.addEventListener('beforescriptexecute', function listener(e){
if(!e.target.src.includes('watch_app.js')) return
document.removeEventListener('beforescriptexecute', listener, true)
e.preventDefault()
e.stopPropagation()
const script = document.createElement('script')
script.src = e.target.src
e.target.parentNode.replaceChild(script, e.target)
}, true)
/*
// HTML内に埋め込まれているJSONの一部を書き換えプレミアムフラグを立てる
*/
document.addEventListener('DOMContentLoaded', () => {
const d = document.getElementById('js-initial-watch-data').dataset
d.apiData = d.apiData.replace('"isPremium":false', '"isPremium":true')
}, true)
/*
// 他タブの動画読み込み状況を読むためのタブ間通信に tab-emitter(https://github.com/ArtskydJ/tab-emitter)を利用している。
// localstorageを利用して通信を行なっているため、そのイベントの発生を阻止する
*/
// window.addEventListener('storage', e => {
// if(e.key !== 'tabemitter') return
// e.stopPropagation()
// e.preventDefault()
// }, true)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment