在草稿箱文章列表标题后边追加醒目提示
当前为
// ==UserScript==
// @name ✨快捷查看微信公众号后台草稿箱文章是否发表
// @version 1.1.2
// @description 在草稿箱文章列表标题后边追加醒目提示
// @author weidingyi
// @match https://mp.weixin.qq.com/cgi-bin/appmsg*action=list_card*
// @match https://mp.weixin.qq.com/cgi-bin/appmsg*action=list*
// @grant unsafeWindow
// @grant GM_xmlhttpRequest
// @connect app.lfeet.asia
// @license MIT
// @namespace https://greasyfork.org/zh-CN/users/1299634-weidingyi
// ==/UserScript==
const window = unsafeWindow
const TK = window.wx ? window.wx.commonData.data.t : '';
(function () {
'use strict';
// 定时发表列表
var time_send_list;
var get_pub_tip = function (flag, title) {
var txt = '';
if (flag) {
txt = "<span style='color:green'> [已发表]</span>";
} else {
// 检查是否在定时发表列表中
txt = "<span style='color:red'> [未发表]</span>";
title = filter_special_chars(title)
let isEq = time_send_list.some(function (item) {
item = filter_special_chars(item);
return item == title;
});
if (isEq) {
txt = "<span style='color:#f313d9'> [定时发表中]</span>"
}
}
return txt;
};
var filter_special_chars = function (str) {
// 匹配空格、!、~ 并替换为空字符串
return str.replace(/[\s+! !~]/g, '');
}
/**
* escape === false时, 为decode, 反之为encode
*/
var escape = function (str, escape) {
// 临时对nickname decode
// var ar=['&','&','<','<','>','>',' ',' ','"','"',"'",''','\\r','<br>','\\n','<br>'];
var ar = ['&', '&', '<', '<', '>', '>', ' ', ' ', '"', '"', '\'', '''];
/*
// 最新版的safari 12有一个BUG,如果使用字面量定义一个数组,var a = [1, 2, 3]
// 当调用了 a.reverse() 方法把变量 a 元素顺序反转成 3, 2, 1 后,
// 即使此页面刷新了, 或者此页面使用 A标签、 window.open 打开的页面,
// 只要调用到同一段代码, 变量 a 的元素顺序都会变成 3, 2, 1
// 所以这里不用 reverse 方法
if (escape === false) {
ar.reverse();
}
*/
var arReverse = [''', '\'', '"', '"', ' ', ' ', '>', '>', '<', '<', '&', '&'];
var target;
if (escape === false) {
target = arReverse;
} else {
target = ar;
}
var r = str;
for (var i = 0; i < target.length; i += 2) {
r = r.replace(new RegExp(target[i], 'g'), target[1 + i]);
}
return r;
}
var get_time_send_list = function () {
let api = "https://mp.weixin.qq.com/cgi-bin/home?t=home/index&token=" + TK + "&lang=zh_CN&f=json";
return fetch(api)
.then(s => s.json())
.then(s => {
let json_timesend_msg = JSON.parse(s.timesend_msg);
if (json_timesend_msg.sent_list.length <= 0) {
return [];
}
let list = json_timesend_msg.sent_list[0].appmsg_info
return list.map(item => {
return item.title;
})
})
}
var fetch_pub_tip = function () {
let list = document.querySelectorAll(".weui-desktop-simple-appmsg__title")
list.forEach(function (item, idx) {
let tip = document.createElement("b");
// 原始标题
let title = item.firstElementChild.textContent;
//去除标题中的特殊字符, 有特殊字符时,搜索不准确, 去之
let keywords = item.textContent.replace('——', '');
let check_api_json = "https://mp.weixin.qq.com/cgi-bin/appmsgpublish?sub=search&begin=0&count=10&token=" + TK + "&query=" + keywords + "&f=json";
// 调用搜索api, 检查是否发表过
fetch(check_api_json)
.then(res => res.json())
.then(res => {
let json_publish_page = JSON.parse(res.publish_page);
let span = '';
if (json_publish_page.total_count > 0) {
span = get_pub_tip(true, title);
} else {
span = get_pub_tip(false, title);
}
tip.innerHTML = span;
item.appendChild(tip);
})
})
}
get_time_send_list()
.then(res => {
time_send_list = res;
fetch_pub_tip();
})
})();
(function () {
let header = document.querySelectorAll(".weui-desktop-global__extra")[1]
const appContainer = document.createElement('button');
appContainer.id = 'btn-run';
appContainer.className = 'weui-desktop-btn weui-desktop-btn_primary';
appContainer.textContent = "生成草稿";
appContainer.style.marginRight = '10px';
appContainer.addEventListener('click', handleGenerateDraft);
// 插入容器
header.prepend(appContainer);
function handleGenerateDraft(e) {
e.target.textContent = "文章模板生成中✨ 保持天天输出~😋";
e.target.disabled = true;
let api = "https://mp.weixin.qq.com/cgi-bin/appmsgpublish?sub=list&begin=0&count=10&token=" + TK + "&lang=zh_CN&f=json";
fetch(api)
.then(s => s.json())
.then(s => {
let json_publish_page = JSON.parse(s.publish_page);
if (json_publish_page.total_count <= 0) {
alert("没有找到最近发布的文章");
e.target.textContent = "生成草稿";
e.target.disabled = false;
return;
}
let list = [];
json_publish_page.publish_list.forEach(item => {
let itemObj = JSON.parse(item.publish_info);
itemObj.appmsg_info.forEach(val => {
list.push({ cover: val.pic_cdn_url_235_1, title: val.title, link: val.content_url });
});
});
// 生成草稿
generateDraft(list);
})
.finally(() => {
e.target.textContent = "生成草稿";
e.target.disabled = false;
});
}
function generateDraft(publish_list) {
const u = window.wx.commonData.data.user_name;
const api = 'https://app.lfeet.asia/preGenArticle';
GM_xmlhttpRequest({
url: api,
method: 'POST',
headers: {'Content-Type': 'application/json; charset=UTF-8', 'Referer': 'mp.weixin.qq.com'},
data: JSON.stringify({'list': publish_list, 'u': u}),
responseType: "json",
onload: obj => {
var data = obj.response;
console.log('remote-resp', data);
location.reload();
},
onerror: err => {
console.error('send-err', err)
}
});
};
})();
const Tool = {
'get_content': function () {
window.__MP_Editor_JSAPI__.invoke({
apiName: 'mp_editor_get_content',
sucCb: (res) => {console.log('设置成功', res)},
errCb: (err) => {console.log('设置失败', err)}
})
},
};