稿定素材

稿定素材库 快速选择素材ID

Versione datata 28/09/2021. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         稿定素材
// @namespace    http://tampermonkey.net/
// @version      0.6
// @description  稿定素材库 快速选择素材ID
// @author       chengguan
// @match        https://*.gaoding.com/*
// @run-at       document-start
// @icon         https://www.google.com/s2/favicons?domain=gaoding.com
// @grant        none
// ==/UserScript==
;(function () {
  'use strict'

  document.addEventListener('DOMContentLoaded', () => {
    // 在素材详情页面
    if (/gaoding.com\/material\/\d+/.test(window.location.href)) {
      const materialId = window.location.href.match(
        /gaoding.com\/material\/(\d+)/,
      )[1]

      document.addEventListener('click', (e) => {
        if (e.metaKey) {
          const avalon = window.open(
            `https://avalon.gaoding.com/c/content/materials/${materialId}`,
          )
        }
      })
    }
  })
  // Your code here...

  document.addEventListener('DOMContentLoaded', () => {
    const selectedIdContainer = document.createElement('div');
    selectedIdContainer.setAttribute('hidden', true);
    selectedIdContainer.style.cssText = `
        position: fixed;
        width: 363px;
        height: 286px;
        border: 1px solid rgb(204, 204, 204);
        z-index: 100;
        top: 100px;
        left: 20px;
        background-color: rgb(238, 238, 238);
        resize: both;
        overflow: auto;
        padding: 10px;
        overflow-wrap: break-word;
        `
    document.body.appendChild(selectedIdContainer);

    document.addEventListener('dblclick', () => {
        selectedIdContainer.toggleAttribute('hidden');
    });

    const ids = new Set()

    document.addEventListener('click', function (e) {
      if (!e.shiftKey) {
        return
      }
      if (e.target.tagName === 'IMG' || e.target.tagName === 'VIDEO') {
        const link = e.target.closest('a')
        if (link && /\/material\/\d+\b/.test(link.href)) {
          e.preventDefault()

          const id = link.href.match(/\b\d+\b/)[0]

          if (ids.has(id)) {
            // 删除
            ids.delete(id)
            link.selectIcon.remove()
          } else {
            // 添加
            ids.add(id)
            toggleSelect(e.target)
          }

          selectedIdContainer.innerHTML = [...ids].join(',')
        }
      }
    })

    function toggleSelect(imageEle) {
      const selectIcon = document.createElement('div')
      selectIcon.style.cssText = `
        position: absolute;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.3);
        text-align: center;
        padding: 20px;
        box-sizing: border-box;
        font-size: 120px;
        color: red;
        text-shadow: 1px 3px 2px #fff;
        pointer-events: none;
        z-index: 5;
        top: 0;
        left: 0;
        font-family: none;
    `
      selectIcon.innerHTML = '✓'
      imageEle.closest('a').appendChild(selectIcon)

      imageEle.closest('a').selectIcon = selectIcon
    }
  })
})()