Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
1.6 kB
194
No Index
Never
// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://danbooru.donmai.us/posts/*
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// ==/UserScript==
(function() {
    'use strict';

    // Your code here...
    const tags = document.getElementsByClassName("tag-type-0");
    let list = [];
    for (let i = 0; i < tags.length; i++) {
        list.push(tags[i].getAttribute("data-tag-name"));
    }

    let string = JSON.stringify(list);
    let remove_ = string.replace(/['"_]+/g, " ");
    let removeBracket = remove_.replace(/\]/g, "");
    let removeOtherBracket = removeBracket.replace(/\[/g, "");

    function download(content, fileName, contentType) {
        var a = document.createElement("a");
        var file = new Blob([content], {
            type: contentType,
        });

        a.href = URL.createObjectURL(file);
        a.download = fileName;

        function doWhichKey(e) {
            e = e || window.event;
            let charCode = e.keyCode || e.which;
            return String.fromCharCode(charCode);
        }

        window.addEventListener(
            "keypress",
            function(e) {
                if (doWhichKey(e) === "]") {
                    a.click();
                }
            },
            false
        );
    }
    download(removeOtherBracket, document.title + '.txt', "text/plain");
})();