素材在avalon打开

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

As of 2021-09-28. See the latest version.

// ==UserScript==
// @name         素材在avalon打开
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  稿定素材库 快速选择素材ID
// @author       You
// @match        https://*.gaoding.com/*
// @run-at          document-start
// @icon         https://www.google.com/s2/favicons?domain=sspai.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.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)

    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: 100;
        top: 0;
        left: 0;
    `
      selectIcon.innerHTML = '✓'
      imageEle.closest('a').appendChild(selectIcon)

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