Copy known words from kitsun.io

Adds a button to copy known words to clipboard

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        Copy known words from kitsun.io
// @namespace   Violentmonkey Scripts
// @match       https://kitsun.io/*
// @grant       none
// @version     0.3
// @author      bspar
// @license     MIT; http://opensource.org/licenses/MIT
// @description Adds a button to copy known words to clipboard
// @require https://cdn.jsdelivr.net/npm/@violentmonkey/dom@2
// ==/UserScript==

var allKnown = '';
var allItems = [];

function clipList(wordListDiv) {
  allItems.forEach((item) => {
    allKnown += item + '\n';
  });
  // japanese parens
  allKnown = allKnown.replace(/[()]/g, '');
  // console.log(allKnown);
  navigator.clipboard.writeText(allKnown);
}

// https://stackoverflow.com/a/29293383
(function(open) {
  XMLHttpRequest.prototype.open = function() {
    this.addEventListener('readystatechange', function() {
      if(this.readyState === 4) {
        if(this.responseURL.includes('https://api.kitsun.io/wordlists?category=')) {
          var obj = JSON.parse(this.responseText);
          allItems = obj.words;
        }
      }
    }, false);
    open.apply(this, arguments);
  };
})(XMLHttpRequest.prototype.open);

// wait for the document to load
const disconnect = VM.observe(document.body, () => {
  // Find the table
  const node = document.querySelector('.word-list');

  // find the header
  if(node) {
    const headerDiv = node.querySelector('.kitTableHeader');
    if(headerDiv) {
      const exportBtn = document.createElement('div');
      exportBtn.classList.add('th');
      exportBtn.textContent = 'Copy to clipboard';
      exportBtn.addEventListener('click', clipList);
      headerDiv.appendChild(exportBtn);
      return true;
    }
  }
});