Last active
April 22, 2020 11:01
-
-
Save zenHeart/8aec3f90366829afba32858bb38e8daa to your computer and use it in GitHub Desktop.
将网址转换为 inoreader rss 订阅
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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