使用油猴脚本,自动转载博客园文章

Jack_孟 / 2023-08-04 / 原文

今天在网站上看到别人写的快速添加随便和文章,网站如下

网址:https://greasyfork.org/zh-CN/scripts/31329-%E5%8D%9A%E5%AE%A2%E5%9B%AD/code

 

我就想自己是否可以也参考使用,用于转载文章呢?

需要完成以下任务:

添加按钮或链接,触发事件

在触发的事件中获取当前文章标题、内容、网址等信息

打开添加随便页面,把上面的信息自动填充到相应位置

手动选择分类、手动发布随笔。

以前写过一个使用bat发布博客的,今天还是想使用javascript脚本来尝试一把。

 

// ==UserScript==
// @name         博客园快速转载随笔文章
// @namespace    http://tampermonkey.net/
//
// @version      0.1
// @description  快速转载随笔文章!
// @author       JackMeng
//
// @run-at       document-end
// @grant        none
// @require      //cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @require      https://cdn.bootcss.com/jquery/2.2.1/jquery.min.js
// ==/UserScript==


(function() {
    'use strict';

    // Your code here...
    //window.onload = Delay();
    $(document).ready(function(){
        // 在此处执行希望在页面加载完成后执行的操作
        setTimeout(AddWrite,300);

    });
    function AddWrite()
    {
        //debugger;
        var par = document.getElementById("span_userinfo");
        par=document.body;
        var f = par.firstElementChild;

        var a = document.createElement("a");
        a.href="https://i.cnblogs.com/EditPosts.aspx?opt=1";
        a.style="position: fixed; z-index: 99; bottom: 2px; right: 120px;";
        a.target="_blank"
        a.innerText="添加随笔";
        par.insertBefore(a,f);
    }
})();