// ==UserScript== // @name Bangumi-Relationship-Person-Synchronize // @namespace org.binota.scripts.bangumi.brps // @include /https?:\/\/(bgm\.tv|bangumi\.tv|chii\.in)\/subject\/\d+\/edit_detail/ // @version 0.1.0 // @grant none // @description none // @downloadURL https://update.greasyfork.icu/scripts/21573/Bangumi-Relationship-Person-Synchronize.user.js // @updateURL https://update.greasyfork.icu/scripts/21573/Bangumi-Relationship-Person-Synchronize.meta.js // ==/UserScript== "use strict"; const SUBJECT_ID = (window.location.pathname.match(/\/subject\/(\d+)/)[1]); var querySelector = function(selector) { return document.querySelector(selector); }; var querySelectorAll = function(selector) { return document.querySelectorAll(selector); }; var Get = function(url, sync = true) { var req = new XMLHttpRequest(); req.open("GET", url, false); req.send(null); if(req.status === 200) return req.responseText; }; var DecodeHtml = (function() { var _e = document.createElement('div'); return function(value) { _e.innerHTML = value; return _e.childNodes.length === 0 ? "" : _e.childNodes[0].nodeValue; }; // https://stackoverflow.com/questions/1912501 })(); //Wcode Facade var Wcode = function(decodeHtml) { this.html2Json = function(html) { const lis = html.match(/]*>(.+?)<\/li>/g); var infobox = {}; //For each "li" node: for(let li of lis) { //Drop all html li = li.replace(/<.+?>/g, '').trim(); let field = decodeHtml(li.match(/^(.+?):/)[1].trim()); let values = decodeHtml(li.match(/:(.+?)$/)[1].trim()); if(typeof infobox[field] === "undefined") { infobox[field] = []; } infobox[field].push(values); } return infobox; }; this.json2Wcode = function(json) { var wcode = ''; wcode += "{{Infobox\n"; for(let field in json) { wcode += `|${field}= `; if(json[field].length > 1) { wcode += "{\n"; for(let value of json[field]) { wcode += `[${value}]`; wcode += "\n"; } wcode += "}\n"; } else { wcode += json[field] + "\n"; } } wcode += "}}"; return wcode; }; }; //Get Infobox from Subject Page. //(Dependency Injection) var getSubjectInfobox = function($, $a, get, wcode, subjectId) { const page = get(`/subject/${subjectId}`); const infoboxHtml = page.match(/