发表的文章
当前{{currentPage}}页
共{{totalPage}}页
-
{{index+1}}-{{item}}
`
var el=document.createElement('div')
el.innerHTML=text;
document.body.append(el)
const App = {
data() {
return {
articleList: [],
totalPage: 1,
currentPage: 1,
};
},
methods: {
search(){
// 因为每个用户的uid是不一样的,所以我这样存储一下,每个用户的就以key-value的形式存到键值对里面
let uid;
// 通过url地址拿到uid
let url = window.location.href;
try{
let urlArr = url.split("&");
uid = urlArr[1].split("=")[1];
}
catch(err){
console.log("该页面脚本没有相应的功能")
}
if(localStorage.getItem("allAuthorArticleList")){
// 点击的时候先拿到我之前存到localStorage里面的值
let preArticleList = JSON.parse(localStorage.getItem("allAuthorArticleList"));
this.totalPage = Math.ceil(preArticleList[uid].length/20);
// 然后把前面的先存进去
this.articleList = preArticleList[uid];
}
// 拿到当前页面的内容并放到articleList数组里面
let thContentList = document.getElementsByTagName("th");
for(let i=0; i < thContentList.length;i++){
if(i == 0 ){
}else {
this.articleList.push(thContentList[i].innerHTML);
}
}
// 所有读者的列表,最后以key-value存储到localStorage里面
let allAuthorArticleList = {};
allAuthorArticleList[uid] = this.articleList;
console.log(allAuthorArticleList);
localStorage.setItem("allAuthorArticleList",JSON.stringify(allAuthorArticleList));
// let that = this;
// GM_xmlhttpRequest({
// method: "GET",
// responseType: "json",
// url: "https://bbs.tampermonkey.net.cn/home.php?mod=space&uid=2&do=thread&view=me&order=dateline&from=space",
// onload: function (xhr) {
// console.log(xhr);
// // 参考文章https://www.cnblogs.com/huoan/p/9600561.html
// if (xhr.readyState === 4 && xhr.status === 200) {
// // 拿到整个页面
// let allHtmlContent = xhr.responseText;
// let reg = /
[^<]*<\/th>/g;
// let contentList = allHtmlContent.match(reg);
// console.log(contentList)
// } else {
// console.log("获取数据失败");
// }
// },
// });
},
clearContent(){
localStorage.clear();
},
clearYeMianContent(){
this.articleList = []
},
displayContent(){
// 因为每个用户的uid是不一样的,所以我这样存储一下,每个用户的就以key-value的形式存到键值对里面
let uid;
// 通过url地址拿到uid
let url = window.location.href;
try{
let urlArr = url.split("&");
uid = urlArr[1].split("=")[1];
let preArticleList = JSON.parse(localStorage.getItem("allAuthorArticleList"));
this.articleList = preArticleList[uid];
this.totalPage = Math.ceil(preArticleList[uid].length/20);
}
catch(err){
console.log("localStorage里面没有allAuthorArticleList属性,是不是你刚才清除了")
}
},
//控制articleList盒子的显示和隐藏
displayArticleList(){
let divHeZi = document.getElementsByClassName("articleList")[0];
if(divHeZi.style.display == "" || divHeZi.style.display == "block"){
divHeZi.style.display = "none";
} else {
divHeZi.style.display = "block";
}
},
//上一页
pre(){
if(this.currentPage == 1){
alert("默认就是从第一页开始的别点了")
} else {
this.currentPage = this.currentPage - 1;
}
},
// 下一页
next(){
this.currentPage = this.currentPage + 1;
}
}
};
const app = Vue.createApp(App);
app.use(ElementPlus);
app.mount("#app");
}
GM_addStyle(`
#app {
position: absolute;
top: 0vh;
right: 0vw;
background: skyblue;
width: 220px;
z-index:999;
overflow:scroll;
}
.articleList {
display: block;
height:100%;
}
`)
|