思路:
上一次的访问量会保存到cookie中。每次刷新时,都会从cookie中获取上一次的访问量,与当前访问量相减即可。博客主页(所有用户的主页)用的是一个cookie,博文页面(所有用户的所有博文)用的是另一个cookie。一共就这两类cookie。然后我把match的网页写死了,只针对我个人博客的主页运行脚本,其他网站一律不运行脚本。这样就不会冲突了,除非打开多个我个人的博客主页。
我只是做了访问量,也可以推广到其他的数据上,原理都是一样的。
运行结果:
代码实现:
// ==UserScript==
// @name CSDN访问量增量显示
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://blog.csdn.net/zxc120389574
// @grant none
// ==/UserScript==
(function() {
'use strict';
// Your code here...
//document.cookie="count="+333 //将cookie写入客户端
//document.cookie="count="+635 //将cookie写入客户端
//alert(getCookie("count"))
var x=document.getElementById("asideProfile");
var arr = getClassById("asideProfile","data-info d-flex item-tiling"</