// ==UserScript== // @name 金山词霸生词本采集器 // @namespace http://scb.iciba.com/ // @version 0.2 // @description 采集金山词霸生词本(scb.iciba.com)上的单词列表 // @author Bob Green // @match *://*.iciba.com/* // @grant none // @downloadURL none // ==/UserScript== (function() { 'use strict'; var btnStyles = 'position: fixed; z-index: 1000; bottom: 0; right: 0; '; var STORE_KEY = 'wordListCache'; function set (content) { return window.localStorage.setItem(STORE_KEY, content); } function get () { return window.localStorage.getItem(STORE_KEY); } function render () { var wrapElem = document.createElement('div'); wrapElem.style = btnStyles; wrapElem.innerHTML = `
`; document.body.appendChild(wrapElem); wrapElem.querySelector('#icibascb_collect').addEventListener('click', collect); wrapElem.querySelector('#icibascb_show').addEventListener('click', showList); wrapElem.querySelector('#icibascb_clear').addEventListener('click', clear); } function collect () { var els = document.querySelectorAll('.word'); var wordList = Array.from(els).map(el => el.innerText); var stashCache = get() || ''; set((stashCache ? (stashCache + '|') : '') + wordList.join('|')); window.alert('已收集'); } function clear () { set(''); } function showList () { var elem = document.createElement('ul'); var cache = get() || ''; var wordList = cache.split('|'); elem.innerHTML = ''; for (var item of wordList) { var newLine = document.createElement('li'); newLine.innerText = item; elem.appendChild(newLine); } var win = window.open('', 'Word List', 'menubar=no,toolbar=no,location=no,status=no'); win.document.body.appendChild(elem); } render(); })();