// ==UserScript==
// @name Bangumi-Episode-Chinese
// @namespace org.binota.scripts.bangumi.bec
// @description Show Chinese episode name in episode page.
// @include /^https?:\/\/(bgm\.tv|bangumi\.tv|chii\.in)\/ep\/\d+/
// @version 0.1.1
// @grant GM_xmlhttpRequest
// @downloadURL https://update.greasyfork.icu/scripts/19106/Bangumi-Episode-Chinese.user.js
// @updateURL https://update.greasyfork.icu/scripts/19106/Bangumi-Episode-Chinese.meta.js
// ==/UserScript==
'use strict';
const STORAGE_PREFIX = `binota_bec_`;
var $ = function(query) {
return document.querySelector(query);
};
var $a = function(query) {
return document.querySelectorAll(query);
};
var subject = $('h1.nameSingle a').href.match(/\/subject\/(\d+)/)[1];
var episode = window.location.href.match(/\/ep\/(\d+)/)[1];
var storage = new (function(driver) {
this._storage = driver;
this.set = function(key, value) {
this._storage.setItem(`${STORAGE_PREFIX}${key}`, value);
return value;
};
this.get = function(key) {
return this._storage.getItem(`${STORAGE_PREFIX}${key}`);
};
this.remove = function(key) {
this._storage.removeItem(`${STORAGE_PREFIX}${key}`);
return key;
};
})(localStorage);
var episodes = new (function(storage, id) {
var subject = (JSON.parse(storage.get(id)) || {});
this.getTitle = function(episode) {
return subject[episode] || '';
};
this.setTitle = function(episode, title) {
return subject[episode] = title.trim();
};
this.save = function() {
return storage.set(id, JSON.stringify(subject));
};
})(storage, subject);
var writeTitle = function() {
var title = episodes.getTitle(episode);
$('h2.title').innerHTML += ` [刷新中文名缓存]`;
if(title !== '') {
$('h2.title').innerHTML = $('h2.title').innerHTML.replace('