「かんたんコメント」機能が果てしなく気に食わないので、とりあえず人々の利用状況を確認するために作成。
- // ==UserScript==
- // @name nicovideo_player_improvement
- // @version 1.1
- // @include http://www.nicovideo.jp/watch/*
- // @include https://www.nicovideo.jp/watch/*
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- // Copyright waived using CC0 1.0 Universal, 2020 dyknon
- window.eval(`
- if(!window.fetch._replaced){
- let _fetch = window.fetch;
- window.fetch = function(url, init){
- console.log("fetch call: " + url);
- if(
- url.indexOf("http://ads.nicovideo.jp/api/video/getAd.php") == 0 ||
- url.indexOf("https://ads.nicovideo.jp/api/video/getAd.php") == 0
- ){
- //再生前広告ブロック
- return Promise.resolve({
- text:
- () => Promise.resolve(
- '<?xml version="1.0" encoding="UTF-8"?>'
- + '<VAST version="3.0"></VAST>'
- )
- });
- }else if(url.indexOf("https://nmsg.nicovideo.jp/api.json/") == 0){
- //「かんたんコメント」を黒くする
- let request = JSON.parse(init.body);
- let pingmap = {};
- let pingname;
- for(let packet of request){
- if(packet.ping){
- pingname = packet.ping.content;
- }else{
- pingmap[pingname] = packet;
- }
- }
- return _fetch(... arguments).then(res => {
- return {
- json: () => res.json().then(json => {
- let creq;
- for(let packet of json){
- if(packet.ping){
- creq = pingmap[packet.ping.content];
- }else if(
- creq && creq.thread_leaves
- && creq.thread_leaves.fork == 2
- && packet.chat
- ){
- packet.chat.mail = "small black " + packet.chat.mail;
- }
- }
- return json;
- })
- };
- });
- }else{
- return _fetch(... arguments);
- }
- };
- window.fetch._replaced = true;
- }
- `);