Skip to content

Instantly share code, notes, and snippets.

@zenHeart
Last active April 22, 2020 11:01
Show Gist options
  • Select an option

  • Save zenHeart/8aec3f90366829afba32858bb38e8daa to your computer and use it in GitHub Desktop.

Select an option

Save zenHeart/8aec3f90366829afba32858bb38e8daa to your computer and use it in GitHub Desktop.
将网址转换为 inoreader rss 订阅

网址转换为 rss 订阅

  1. 在 rss.js 中添加需要转换为 rss 的链接,各字段含义如下
    1. validator 判断当前网址是否匹配对应的 rss
    2. convert 将当前网址转换为 rss 订阅

      访问 rsshub 查看如何将无法订阅的资源转换为 rss

  2. 将脚本复制到 脚本转换为书签 工具。
  3. 将书签拖动到标签栏,当遇到需要订阅的网址,点击书签即可,点击示例 rss 此链接可能由于无法包含 js 正常在 gist 显示,可以直接查看原始格式复制地址
gi(function () {
let rssData = {
youtube: {
validator: /youtube\.com\/channel/,
urlToRss: (location) =>
`https://rsshub.app//youtube/channel/${location.pathname.split('/')[2]}`
},
twitter: {
validator: /twitter\.com/,
urlToRss: (location) =>
`https://rsshub.app/twitter/user/${location.pathname.split('/')[1]}`
},
zhihu: {
validator: /zhuanlan\.zhihu/,
urlToRss: (location) => {
let path = '';
if (location.pathname.includes('/p/')) {
path = document
.querySelector('.ColumnLink.ColumnPageHeader-Link')
.getAttribute('href');
} else {
path = location.pathname;
}
return `https://rss.lilydjwg.me/zhihuzhuanlan${path}`;
}
},
githubIssue: {
validator: /github\.com\.*issues/,
urlToRss: (location) =>
`https://rsshub.app/github/issue/${location.pathname
.split('/')
.slice(1, 3)
.join('/')}`
}
};
let validatorRss = (url, validator) => validator.test(url);
let addRss = (url) => `https://www.inoreader.com/?add_feed=${url}`;
let subscribe = (a, w, h) => {
var b = window.screenLeft != undefined ? window.screenLeft : screen.left;
var c = window.screenTop != undefined ? window.screenTop : screen.top;
width = window.innerWidth
? window.innerWidth
: document.documentElement.clientWidth
? document.documentElement.clientWidth
: screen.width;
height = window.innerHeight
? window.innerHeight
: document.documentElement.clientHeight
? document.documentElement.clientHeight
: screen.height;
var d = width / 2 - w / 2 + b;
var e = height / 2 - h / 2 + c;
var f = window.open(
a,
new Date().getTime(),
'width=' +
w +
', height=' +
h +
', top=' +
e +
', left=' +
d +
'location=yes,resizable=yes,status=no,scrollbars=no,personalbar=no,toolbar=no,menubar=no'
);
if (window.focus) {
f.focus();
}
};
let l = location;
let res;
for (let k in rssData) {
let rss = rssData[k];
if (validatorRss(l.href, rss.validator)) {
res = rss.urlToRss(l);
}
}
if (res) {
subscribe(
'https://www.inoreader.com/bookmarklet/subscribe/' +
encodeURIComponent(res),
640,
400
);
} else {
subscribe(
'https://www.inoreader.com/bookmarklet/subscribe/' +
encodeURIComponent(location.href),
640,
400
);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment