// ==UserScript== // @name 条目页快捷创建角色并关联 // @namespace https://bgm.tv/group/topic/435747 // @homepage https://bgm.tv/group/topic/435747 // @version 0.0.2 // @description 条目角色页添加创建按钮,创建后自动跳转到关联页面并将新角色列入其中 // @author you // @icon https://bgm.tv/img/favicon.ico // @match http*://bgm.tv/subject/* // @match http*://bgm.tv/subject/*/characters // @match http*://bgm.tv/character/new // @match http*://bgm.tv/character/* // @match http*://bgm.tv/subject/*/add_related/character* // @match http*://bangumi.tv/subject/* // @match http*://bangumi.tv/subject/*/characters // @match http*://bangumi.tv/character/new // @match http*://bangumi.tv/character/* // @match http*://bangumi.tv/subject/*/add_related/character* // @match http*://chii.in/subject/* // @match http*://chii.in/subject/*/characters // @match http*://chii.in/character/new // @match http*://chii.in/character/* // @match http*://chii.in/subject/*/add_related/character* // @grant none // @license MIT // @gf https://greasyfork.org/zh-CN/scripts/549613 // @gadget https://bgm.tv/dev/app/3465 // @downloadURL https://update.greasyfork.icu/scripts/549613/%E6%9D%A1%E7%9B%AE%E9%A1%B5%E5%BF%AB%E6%8D%B7%E5%88%9B%E5%BB%BA%E8%A7%92%E8%89%B2%E5%B9%B6%E5%85%B3%E8%81%94.user.js // @updateURL https://update.greasyfork.icu/scripts/549613/%E6%9D%A1%E7%9B%AE%E9%A1%B5%E5%BF%AB%E6%8D%B7%E5%88%9B%E5%BB%BA%E8%A7%92%E8%89%B2%E5%B9%B6%E5%85%B3%E8%81%94.meta.js // ==/UserScript== (function () { 'use strict'; const pathname = location.pathname; const exposeEntry = () => { const a = document.createElement('a'); a.classList.add('l'); a.textContent = '/ 创建角色到关联'; a.href = '/character/new'; const br = document.createElement('br'); document.querySelector(':where(#columnInSubjectB, #columnCrtRelatedB) .menu_inner:nth-of-type(2), .modifyTool .tip_i p:nth-of-type(2)').append(br, a); }; if (pathname.endsWith('characters') || pathname.match(/^\/subject\/\d+$/)) { // 条目角色页或条目页 exposeEntry(); } else if (pathname.endsWith('new')) { // 创建角色页 const referrer = document.referrer; const sbjId = referrer.match(/subject\/(\d+)/)?.[1]; if (!sbjId) return; sessionStorage.setItem('crtRelSbjId', sbjId); } else if (pathname.match(/^\/character\/\d+$/)) { // 创建好的角色页 const sbjId = sessionStorage.getItem('crtRelSbjId'); if (!sbjId) return; sessionStorage.removeItem('crtRelSbjId'); const crtId = pathname.match(/\d+/)[0]; const crtName = document.querySelector('#headerSubject a').textContent; location.href = `${location.origin}/subject/${sbjId}/add_related/character?id=${crtId}&name=${encodeURIComponent(crtName)}`; } else if (pathname.endsWith('character')) { // 条目关联页 exposeEntry(); const params = new URLSearchParams(location.search); const crtId = params.get('id'); if (!crtId) return; const crtName = decodeURIComponent(params.get('name')); const ul = document.querySelector('#crtRelateSubjects'); ul.insertAdjacentHTML('afterbegin', `
  • x

    ${crtName}

    类型: 参与: 排序:
  • `); } })();