3. 【参考文档】如何剪藏《汉表服务系统》的主题词

已过时(将来可能会更新)


- 步骤1:复制代码:复制下面的 JavaScript 代码片段
- 步骤2:保存为代码片段:将复制的内容保存为浏览器的开发者工具的`代码片段`,需要使用 `Ctrl+P` 和键入 `>`  调出命令面板搜索  `创建新的代码片段` 来运行
- 步骤3:在需要时运行片段:在[《汉表服务系统网站》](https://ct.istic.ac.cn/site/organize/word)的一个主题词的详细信息页,在需要时使用`Ctrl+P` 和键入 `! ` 来搜索该片段的名称来运行
- 步骤4:保存笔记:复制控制台输出的文本,保存为 Markdown 笔记,并且存放到目录 `data/82 汉语主题词表/主题词`
- 步骤5:整理笔记:创建或整理相关的分类笔记

```js
"use strict";
function main() {     
    var webClipper = DescriptorWebClipper.getInstance();
    const wordTablesStr = webClipper.getWordTablesStr();
    console.log(wordTablesStr)
}

var DescriptorWebClipper = /** @class */ (function () {
    function DescriptorWebClipper() {
    }
    DescriptorWebClipper.getInstance = function () {
        return this.instance;
    };
    DescriptorWebClipper.prototype.getWordTablesStr = function () {
        return Array.from(document.querySelectorAll("table.table-bordered")).map(function (t) { return new DescriptorInfoTable(t).getWordTableStr(); }).join("\n\n");
    };
    DescriptorWebClipper.instance = new DescriptorWebClipper();
    return DescriptorWebClipper;
}());


var DescriptorInfoTable = /** @class */ (function () {
    function DescriptorInfoTable(t) {
        this.sources = [];
        this.classifications = [];
        this.english = "";
        this.synonyms = [];
        this.broadTerms = [];
        this.relatedTerms = [];
        this.narrowerTerms = [];
        this.aliases = [];
        this.t = t;
    }
    DescriptorInfoTable.prototype.getWordTableStr = function () {
        var _this = this;
        this.t.querySelectorAll("tr").forEach(function (tr) {
            var th = tr.querySelector("th");
            var td = tr.querySelector("td");
            if (!th || !td) {
                throw new TypeError("TypeError: ( !th || !td ) === true");
            }
            var thText = th.innerText;
            var tdText = td.innerText;
            var tdItemArr = tdText.split("、");
            if (thText === DescriptorInfoTable.field.sources) {
                _this.sources = tdItemArr;
            }
            else if (thText === DescriptorInfoTable.field.classifications) {
                _this.classifications = tdText.split(/、(?:[A-Z])/g);
            }
            else if (thText === DescriptorInfoTable.field.english) {
                _this.english = tdText;
            }
            else if (thText === DescriptorInfoTable.field.synonyms) {
                _this.synonyms = tdItemArr;
            }
            else if (thText === DescriptorInfoTable.field.broadTerms) {
                _this.broadTerms = tdItemArr;
            }
            else if (thText === DescriptorInfoTable.field.relatedTerms) {
                _this.relatedTerms = tdItemArr;
            }
            else if (thText === DescriptorInfoTable.field.narrowerTerms) {
                _this.narrowerTerms = tdItemArr;
            }
            else {
                _this[thText] = tdText;
            }
        });
        if (this.synonyms) {
            this.aliases = Array.from(this.synonyms);
            if (this.english) {
                this.aliases.push(this.english);
            }
        }
        else {
            this.aliases = [this.english];
        }
        if (this.english === "saline water;salt brine;saltwater;salt-water") {
            return "";
        }
        var orderedKeys = [
            "sources", "classifications", "english",
            "synonyms", "broadTerms", "narrowerTerms", "relatedTerms"
        ];
        var str1 = "# " + document.querySelectorAll('.col-md-6>h3')[0].textContent + "\n";
        var str2 = "| | |\n| --- | --- |\n" + orderedKeys.map(function (key) {
            if (key === "english") {
                return "| " + DescriptorInfoTable.field.english + " | " + _this.english + " |";
            }
            else if (["broadTerms", "narrowerTerms", "relatedTerms"].some(function (w) { return w === key; })) {
                //const value02 = (value as string[]).map(w => "[[" + w + "]]").join("、")
                var _a = _this.getEntry(key), key2 = _a.key2, value2 = _a.value2;
                if (value2.length === 0) {
                    return "";
                }
                var value2Str = value2.map(function (w) { return "[[" + w + "]]"; }).join("、");
                return "| " + key2 + " | " + value2Str + "|";
            }
            else if (["sources", "synonyms", "classifications"].some(function (w) { return w === key; })) {
                var _b = _this.getEntry(key), key2 = _b.key2, value2 = _b.value2;
                if (value2.length === 0) {
                    return "";
                }
                var value2Str = value2.join("、");
                return "| " + key2 + " | " + value2Str + "|";
            }
            return "";
        }).filter(function (s) { return s.length > 0; }).join("\n") + "\n";
        var str3 = "```yaml\n---\n" + orderedKeys.map(function (key) {
            var value = _this[key];
            if (key === "english") {
                var key2 = DescriptorInfoTable.field.english;
                var value2Str = value;
                key2 = "主题词-" + key2;
                return  key2 + ": " + value2Str;
            }
            else if (["broadTerms", "narrowerTerms", "relatedTerms"].some(function (w) { return w === key; })) {
                var _a = _this.getEntry(key), key2 = _a.key2, value2 = _a.value2;
                key2 = "主题词-" + key2;
                if (value2.length === 0) {
                    return key2 + ":";
                }
                var value2Str = value2.map(function (w) { return '  - "[[' + w + ']]"'; }).join("\n");
                return key2 + ":\n" + value2Str;
            }
            else if (["sources", "synonyms", "classifications"].some(function (w) { return w === key; })) {
                var _b = _this.getEntry(key), key2 = _b.key2, value2 = _b.value2;
                key2 = "主题词-" + key2;
                if (value2.length === 0) {
                    return key2 + ":";
                }
                var value2Str = value2.map(function (w) { return '  - ' + w + ''; }).join("\n");
                return key2 + ":\n" + value2Str;
            }
        }).join("\n") + "\n" + "aliases:\n" + this.aliases.map(function (w) { return '  - ' + w + ''; }).join("\n") + "\n---\n```\n";
        return [str1, str2, str3].join("\n");
    };
    DescriptorInfoTable.prototype.getEntry = function (key) {
        var key2;
        var value2;
        if (key === "broadTerms") {
            key2 = DescriptorInfoTable.field.broadTerms;
            value2 = this.broadTerms;
        }
        else if (key === "narrowerTerms") {
            key2 = DescriptorInfoTable.field.narrowerTerms;
            value2 = this.narrowerTerms;
        }
        else if (key === "relatedTerms") {
            key2 = DescriptorInfoTable.field.relatedTerms;
            value2 = this.relatedTerms;
        }
        else if (key === "sources") {
            key2 = DescriptorInfoTable.field.sources;
            value2 = this.sources;
        }
        else if (key === "synonyms") {
            key2 = DescriptorInfoTable.field.synonyms;
            value2 = this.synonyms;
        }
        else if (key === "classifications") {
            key2 = DescriptorInfoTable.field.classifications;
            value2 = this.classifications;
        }
        else {
            throw new Error("Unknown key: ".concat(key));
        }
        return { key2: key2, value2: value2 };
    };
    DescriptorInfoTable.field = {
        sources: "来源", // String Array
        english: "英文", // String | prop 03
        synonyms: "同义词", // String Array | prop 05
        broadTerms: "上位词", // Link Array | prop 06
        narrowerTerms: "下位词", // Link Array | prop 07
        relatedTerms: "相关词", // Link Array | prop 08
        classifications: "分类" // Link Array | prop 31
    };
    return DescriptorInfoTable;
}());

main();

```