用户:
lsk666666查看:1 回复:3 评论:1 创建时间:2021-06-20T19:45:46
写了一个喵的东西,原理是重新加载内容元素的内容。
放源码~
油猴插件部分:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://shequ.codemao.cn/wiki/forum/*
// @icon https://www.google.com/s2/favicons?domain=codemao.cn
// @grant none
// @require http://code.jquery.com/jquery-1.11.0.min.js
// ==/UserScript==
(function() {
'use strict';
// Your code here...
// Wait for loading complete
setTimeout(() => {
let href = window.location.href
let parts = href.split("/")
let url = "http://localhost:5000/detail/" + parts[parts.length - 1]
$.ajax({
url: url,
method: "GET",
success: function (resp) {
console.log(resp)
$(".r-community-r-detail--forum_content").html(resp)
}
})
}, 1000)
})();
python后台:
from flask import Flask
import requests
from flask_cors import CORS
app = Flask(__name__)
CORS(app, supports_credentials=True)
@app.route("/detail/<pid>")
def serv(pid):
resp = requests.get("https://api.codemao.cn/web/forums/posts/" + str(pid) + "/details")
return resp.json()["content"]
if __name__ == "__main__":
app.run(host="0.0.0.0")
加后台是因为我做测试时发现编程猫这坑爹的api没允许跨域,我暂时没整明白怎么配置Nginx让他代理含有路径参数的URL,就自己用Python做了个相当于代理的程序给他加上跨域的Header
修改:
1. require的内容是jquery的cdn地址
2. namespace的内容是http://tampermonkey。net(故意打成这样的)
3.第七行后面加上
// @match https://shequ.codemao.cn/community/*点赞1
评论