作文网作文下载器(作文,论文,计划书,文章下载)【python学霸公众号】

网页作文下载器

// ==UserScript==
// @name         作文网作文下载器(作文,论文,计划书,文章下载)【python学霸公众号】
// @namespace    Pyhton学霸
// @version      0.1
// @description  网页作文下载器
// @match        *://*/*
// @grant        GM_xmlhttpRequest
// @grant        GM_download
// ==/UserScript==

(function() {
    'use strict';

    function downloadText(url) {
        GM_xmlhttpRequest({
            method: "GET",
            url: url,
            onload: function(response) {
                var parser = new DOMParser();
                var htmlDoc = parser.parseFromString(response.responseText, "text/html");
                var title = htmlDoc.querySelector("div.tit").textContent.trim();
                var content = htmlDoc.querySelector("div.content").textContent.trim();

                var fileContent = title + "\n" + content;
                var fileName = title + ".txt";

                GM_download({
                    url: "data:text/plain;charset=utf-8," + encodeURIComponent(fileContent),
                    name: fileName
                });
            }
        });
    }

    function createDownloadButton() {
        var currentUrl = window.location.href;
        if (currentUrl.includes('chazidian.com')) {
            var button = document.createElement("button");
            button.innerText = "下载作文(学霸免VIP)";
            button.style.backgroundColor = "#ffdf00";
            button.style.border = "none";
            button.style.borderRadius = "10%";
            button.style.color = "#fff";
            button.style.fontSize = "16px";
            button.style.padding = "10px 20px";
            button.style.position = "fixed";
            button.style.right = "50px";
            button.style.top = "50%";
            button.style.transform = "translateY(-50%)";
            button.addEventListener("click", function() {
                downloadText(currentUrl);
            });

            document.body.appendChild(button);
        }
    }

    createDownloadButton();
})();