知乎推文小助手(需要盐选)

zhihu.com自动下载推文

// ==UserScript==
// @name         知乎推文小助手(需要盐选)
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  zhihu.com自动下载推文
// @author       赫尔
// @match        https://www.zhihu.com/market/*
// @icon         
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    const createUI = ()=>{
        // Create the panel and its elements
        const downloadPanel = document.createElement('div');
        const downloadBtn = document.createElement('button');
        const downloadCloseBtn = document.createElement('button');

        downloadPanel.style.position = 'fixed';
        downloadPanel.style.top = '10px';
        downloadPanel.style.right = '10px';
        downloadPanel.style.zIndex = '9999';
        downloadPanel.style.backgroundColor = '#f5f5f5';
        downloadPanel.style.border = '1px solid #ddd';
        downloadPanel.style.padding = '10px';
        downloadPanel.style.display = 'block';
        downloadPanel.innerHTML = '<h2>下载面板</h2><p>点击按钮开始下载正片文章。(需要盐选会员)</p>';

        downloadBtn.innerHTML = 'Download';
        downloadBtn.style.marginRight = '10px';

        downloadCloseBtn.innerHTML = 'close';
        downloadCloseBtn.style.float = 'right';

        // Add the elements to the panel
        downloadPanel.appendChild(downloadCloseBtn);
        downloadPanel.appendChild(downloadBtn);

        // Attach the panel to the body
        document.body.appendChild(downloadPanel);

        // Define the download function
        function downloadFile() {
            downloadArticel()
        }

        // download when the download button is clicked
        downloadBtn.addEventListener('click', function() {
            downloadFile()
        });

        // Hide the panel when the close button is clicked
        downloadCloseBtn.addEventListener('click', function() {
            downloadPanel.style.display = 'none';
        });
    }

    const g = (name) => {
        return document.getElementsByClassName(name)[0]
    }

    function download(filename, text) {
        var element = document.createElement('a');
        element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
        element.setAttribute('download', filename);
        element.style.display = 'none';
        document.body.appendChild(element);
        element.click();
        document.body.removeChild(element);
    }



    const removeSelectBlock =() => {
        //取消无法选中
        const className = 'ManuscriptIntro-root-sYjqt';
        let div = g(className)
        div.style.userSelect = 'auto'
        div.style.webkitUserSelect = 'auto'


    }

    window.onload = ()=>{
        createUI()
        removeSelectBlock();
        console.log('ok')
    }


})();