aboutsummaryrefslogtreecommitdiff
path: root/content_scripts
diff options
context:
space:
mode:
authorMark Powers <mark@marks.kitchen>2022-12-29 14:03:57 -0600
committerMark Powers <mark@marks.kitchen>2022-12-29 14:03:57 -0600
commitb5c10718ddeaa8fcac368515ca150705b1a2c5ab (patch)
tree473c6b8197774ed3a29df73821c404381535ccbc /content_scripts
parentff9f53e5673d742d155881a2a29f31ba312dce9c (diff)
Refactor scripts, add table preview
Diffstat (limited to 'content_scripts')
-rw-r--r--content_scripts/bridges/instagram.js10
-rw-r--r--content_scripts/bridges/twitter.js12
-rw-r--r--content_scripts/bridges/youtube.js63
-rw-r--r--content_scripts/cs.js86
4 files changed, 171 insertions, 0 deletions
diff --git a/content_scripts/bridges/instagram.js b/content_scripts/bridges/instagram.js
new file mode 100644
index 0000000..0ced06a
--- /dev/null
+++ b/content_scripts/bridges/instagram.js
@@ -0,0 +1,10 @@
+async function get_insta() {
+ let url = window.location.href;
+ let insta_url = url + "?__a=1"
+ let res = await fetch(insta_url);
+ let json = await res.json();
+ let uid = json.graphql.user.id
+ let feed_url = `${base_url}/?action=display&bridge=Instagram&context=Username&u=${uid}&media_type=all&format=`;
+ return get_all_types(feed_url)
+}
+
diff --git a/content_scripts/bridges/twitter.js b/content_scripts/bridges/twitter.js
new file mode 100644
index 0000000..e9855cb
--- /dev/null
+++ b/content_scripts/bridges/twitter.js
@@ -0,0 +1,12 @@
+function get_twitter() {
+ let url = window.location.href;
+ let pattern = /twitter.com\/(\w+).*/
+ let match = url.match(pattern);
+ if (match) {
+ let twitter_handle = match[1]
+ let feed_url = `${base_url}/?action=display&bridge=Twitter&context=By+username&u=${twitter_handle}&format=`
+ return get_all_types(feed_url)
+ }
+ return []
+}
+
diff --git a/content_scripts/bridges/youtube.js b/content_scripts/bridges/youtube.js
new file mode 100644
index 0000000..202873b
--- /dev/null
+++ b/content_scripts/bridges/youtube.js
@@ -0,0 +1,63 @@
+function get_native_playlist_feed(playlistId){
+ return `https://www.youtube.com/feeds/videos.xml?playlist_id=${playlistId}`
+}
+
+function get_native_channel_feed(channelId){
+ return `https://www.youtube.com/feeds/videos.xml?channel_id=${channelId}`
+}
+
+async function get_youtube() {
+ let url = window.location.href;
+
+ let patternVideo = /youtube.com\/watch\?v=[A-z0-9-_]+/
+ let matchVideo = url.match(patternVideo)
+
+ let patternUser = /youtube.com\/user\/[A-z0-9-_]+.*/
+ let matchUser = url.match(patternUser)
+
+ let patternChannel = /youtube.com\/channel\/[A-z0-9-_]+.*/
+ let matchChannel = url.match(patternChannel)
+
+ let patternPlaylist = /youtube.com\/playlist\?list=[A-z0-9-_]+.*/
+ let matchPlaylist = url.match(patternPlaylist)
+
+ if (matchVideo) {
+ let channel_url = document.querySelector("[role='main'] #channel-name a")["href"]
+ let matchChannel2 = channel_url.match(patternChannel)
+ let channelId = matchChannel2[1]
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+channel+id&c=${channelId}&duration_min=&duration_max=&format=`
+ let native_url = get_native_channel_feed(channelId)
+ let feeds = get_all_types(feed_url, "channel").concat([{ type: `native (channel): Rss`, url: native_url }])
+
+ let patternListInVideo = /youtube.com\/watch\?v=\w+\&list=(\w+)/
+ let matchListInVideo = url.match(patternListInVideo)
+ if(matchListInVideo){
+ let playlistId = matchListInVideo[1]
+ let playlist_feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+playlist+Id&p=${playlistId}&duration_min=&duration_max=&format=`
+ let native_url = get_native_playlist_feed(playlistId)
+ let rb_feeds = get_all_types(playlist_feed_url, "playlist")
+ feeds = feeds.concat(rb_feeds.concat([{ type: `native (playlist): Rss`, url: native_url }]))
+ }
+
+ return feeds
+ }
+ if (matchUser) {
+ let user = matchUser[1];
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+username&u=${user}&duration_min=&duration_max=&format=`
+ return get_all_types(feed_url)
+ }
+ if (matchChannel) {
+ let channelId = matchChannel[1]
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+channel+id&c=${channelId}&duration_min=&duration_max=&format=`
+ return get_all_types(feed_url)
+ }
+ if (matchPlaylist) {
+ let playlistId = matchPlaylist[1]
+ let native_url = get_native_playlist_feed(playlistId)
+ let feed_url = `${base_url}/?action=display&bridge=Youtube&context=By+playlist+Id&p=${playlistId}&duration_min=&duration_max=&format=`
+ let rb_feeds = get_all_types(feed_url)
+ return rb_feeds.concat([{ type: `native: Rss`, url: native_url }])
+ }
+ return []
+}
+
diff --git a/content_scripts/cs.js b/content_scripts/cs.js
new file mode 100644
index 0000000..e57176b
--- /dev/null
+++ b/content_scripts/cs.js
@@ -0,0 +1,86 @@
+var base_url = undefined
+let formats = ["Atom", "Mrss", "Html"]
+let types = {
+ 'application/rss+xml': "rss",
+ 'application/atom+xml': "atom",
+ 'application/rdf+xml': "rdf",
+ 'application/rss': "rss",
+ 'application/atom': "atom",
+ 'application/rdf': "rdf",
+ 'text/rss+xml': "rss",
+ 'text/atom+xml': "atom",
+ 'text/rdf+xml': "rdf",
+ 'text/rss': "rss",
+ 'text/atom': "atom",
+ 'text/rdf': "rdf"
+}
+
+
+function find_links_in_page() {
+ let links = document.querySelectorAll('link[type]');
+ let feeds = [];
+ for (let i = 0; i < links.length; i++) {
+ if (links[i].hasAttribute('type') && links[i].getAttribute('type') in types) {
+ let title = links[i].getAttribute('title')
+ let href = links[i].getAttribute('href')
+ let feed_url = new URL(href, window.location.href).href
+ let type = types[links[i].getAttribute('type')]
+ let feed = {
+ type: `native: ${title || type}`,
+ url: feed_url,
+ };
+ feeds.push(feed);
+ }
+ }
+ return feeds
+}
+
+function get_all_types(feed_url, note) {
+ let feeds = [];
+ formats.forEach(el => {
+ if(note){
+ feeds.push({
+ type: `rss-bridge (${note}): ${el}`,
+ url: feed_url + el
+ });
+ } else {
+ feeds.push({
+ type: `rss-bridge: ${el}`,
+ url: feed_url + el
+ });
+ }
+ })
+ return feeds;
+}
+
+let objs = []
+
+async function get_feed_urls() {
+ let settings = await browser.storage.sync.get("rb");
+ base_url = settings.rb;
+ let all_feed_urls = []
+ let host = window.location.host;
+ for (const obj of objs) {
+ for (const obj_host of obj.hosts) {
+ if (host.includes(obj_host)) {
+ result = await obj.callback()
+ all_feed_urls = all_feed_urls.concat(result)
+ break
+ }
+ }
+ }
+ all_feed_urls = all_feed_urls.concat(find_links_in_page())
+ return all_feed_urls
+}
+
+function register(hosts, callback) {
+ objs.push({hosts, callback})
+}
+
+register(["instagram"], get_insta)
+register(["twitter"], get_twitter)
+register(["youtube"], get_youtube)
+
+browser.runtime.onMessage.addListener(function (msg, sender) {
+ return Promise.resolve(get_feed_urls());
+})