// ==UserScript==
// @name 「Feedly」- 中键标记已读 + 收藏导出为*.url
// @namespace https://www.wdssmq.com/
// @author 沉冰浮水
// @version 0.3.5
// @description 新标签页打开条目时自动标记为已读,收藏计数
// ----------------------------
// @raw https://github.com/wdssmq/userscript/tree/master/feedly
// @raw https://greasyfork.org/zh-CN/scripts/381793
// ----------------------------
// @link https://afdian.net/@wdssmq
// @link https://github.com/wdssmq/userscript
// @link https://greasyfork.org/zh-CN/users/6865-wdssmq
// ----------------------------
// @match https://feedly.com/*
// @grant GM_openInTab
// @grant GM_setClipboard
// @downloadURL none
// ==/UserScript==
/*jshint esversion: 6 */
(function () {
"use strict";
function $n(e) {
return document.querySelector(e);
}
function $na(e) {
return document.querySelectorAll(e);
}
function addEvent(element, evnt, funct) {
return element.addEventListener(evnt, funct, false);
}
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
// 拿回订阅源地址
// 绑定监听事件到 div#box 上
addEvent($n("#box"), "mouseup", function (event) {
// 输出触发事件的元素
console.log(event.target);
// 根据内容判断是否执行相应操作
const elText = event.target.innerHTML;
if (
// elText.indexOf("Feed not found") > -1 ||
elText.indexOf("Wrong feed URL") > -1
) {
// 内部再输出一次确定判断条件正确
console.log(event.target);
// 拿到解码后的订阅源地址
const curUrl = ((url) => {
return url.replace("https://feedly.com/i/subscription/feed/", "");
})(decodeURIComponent(location.href));
// 输出到页面中
$n("#feedlyPageFX h2").insertAdjacentHTML(
"beforeend",
`
${curUrl}
`
);
}
});
// 星标文章导出为 *.url 文件
function fnMKShell($list) {
const today = new Date(); //获得当前日期
const year = today.getFullYear(); //获得年份
const month = today.getMonth() + 1; //此方法获得的月份是从0---11,所以要加1才是当前月份
const day = today.getDate(); //获得当前日期
const arrDate = [year, month, day];
let strRlt =
'if [ ! -d "foldername" ]; then\n' +
"mkdir foldername\n" +
"fi\n" +
"cd foldername\n";
strRlt = strRlt.replace(/foldername/g, "later-" + arrDate.join("-"));
$list.forEach(function (e, i) {
// console.log(e);
let strTitle = `${i}丨`;
strTitle += e.textContent.replace(/\\|\/|:|\*|!|\?]|<|>/g, "");
const lenTitle = strTitle.length;
if (lenTitle >= 155) {
strTitle = `${i}丨标题过长丨${lenTitle}`;
}
let strUrl = e.href;
// strRlt += `\n#${i} - ${lenTitle}\n`;
strRlt += 'echo [InternetShortcut] > "' + strTitle + '.url"\n';
strRlt += 'echo "URL=' + strUrl + '" >> "' + strTitle + '.url"\n';
});
strRlt += "exit\n\n";
strRlt = strRlt.replace(/\/\/\//g, "//www.bilibili.com/");
//console.log(strRlt);
return strRlt;
//$n("body").innerHTML = strRlt.replace(/\n/g, "
");
}
addEvent($n("#box"), "mouseup", function (event) {
if (
event.target.innerHTML.indexOf("Read later") > -1
) {
const $el = event.target;
console.log($el);
fnOnScroll();
GM_setClipboard(fnMKShell($na("div.content a")));
}
});
// 加载完成后激活计数
window.onload = async function () {
while (!fnOnScroll()) {
console.log("waiting……");
await sleep(3000);
}
}
// 星标计数
function fnOnScroll() {
if ($n("#feedlyFrame") && $n("#feedlyFrame").dataset.addEL !== "done") {
$n("#feedlyFrame").dataset.addEL = "done";
$n("#feedlyFrame").addEventListener('scroll', function () {
console.log(location.href);
if ('https://feedly.com/i/saved' == location.href) {
let intCount = $na("div.content a").length;
$n("h1 #header-title").innerHTML = `Read later(${intCount})`;
$n("h2.Heading").innerHTML = `Read later(${intCount})`;
}
});
console.log("计数事件- 启用成功");
return true;
}
console.log("计数事件 - 页面加载中");
return false
}
// 自动标记已读
var opt1 = 0;
addEvent($n("#box"), "mouseup", function (event) {
if (
event.target.className === "link entry__title" &&
event.target.nodeName === "A"
) {
console.log(event.target);
const $btn = event.target.parentNode.querySelector(
".EntryMarkAsReadButton"
);
// if ($btn.title === "Mark as read") {
console.log($btn.title);
console.log("自动标记已读");
$btn.click();
// }
if (event.button !== 1 && opt1) {
GM_openInTab(event.target.href, true);
}
}
});
return;
})();