-
-
Save nathandaven/76fd9c1e9e7c30eaea29003120acb4ae to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // ==UserScript== | |
| // @name Open Apollo App Live Container | |
| // @version 1.0.0 | |
| // @author nathandaven | |
| // @match *://*.reddit.com/* | |
| // @downloadURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-apollo-live-container.user.js | |
| // @updateURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-apollo-live-container.user.js | |
| // @homepage https://github.com/nathandaven/Open-In-Apollo-Live-Container/tree/main | |
| // ==/UserScript== | |
| // need to encode the string to base64 for live container link to work | |
| function utf8_to_b64(str) { | |
| return window.btoa(unescape(encodeURIComponent(str))); | |
| } | |
| function openInApollo() { | |
| const regexRedditIDs = | |
| /^(?:https?:\/\/)?(?:(?:www|amp|m|i)\.)?(?:(?:reddit\.com))\/r\/(\w+)(?:\/comments\/(\w+)(?:\/\w+\/(\w+)(?:\/?.*?[?&]context=(\d+))?)?)?/i; | |
| const match = window.location.href.match(regexRedditIDs); | |
| if ( | |
| window.location.pathname === "/" || | |
| window.location.pathname === "/?feed=home" | |
| ) { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("apollo://"); | |
| return; | |
| } | |
| if (window.location.pathname.includes("/search")) { | |
| return; | |
| } | |
| if (match) { | |
| const newRegex = /\/new.*/; | |
| const endsInNew = newRegex.test(window.location.pathname); | |
| if (endsInNew) { | |
| newPath = window.location.pathname.slice(0, -4); | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`apollo://${window.location.hostname}${newPath}`); | |
| return; | |
| } | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64( | |
| `apollo://${window.location.hostname}${window.location.pathname}` | |
| ); | |
| } | |
| } | |
| openInApollo(); |
This file contains hidden or 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
| // ==UserScript== | |
| // @name Open in Instagram Live Container | |
| // @version 1.0.0 | |
| // @author nathandaven | |
| // @match *://*.instagram.com/* | |
| // @downloadURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-instagram-app-live-container.user.js | |
| // @updateURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-instagram-app-live-container.user.js | |
| // @homepage https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae | |
| // ==/UserScript== | |
| // need to encode the string to base64 for live container link to work | |
| function utf8_to_b64(str) { | |
| return window.btoa(unescape(encodeURIComponent(str))); | |
| } | |
| function openInInstagram() { | |
| let redirect = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64( | |
| document.querySelector('[property="al:ios:url"]')?.getAttribute("content") | |
| ); | |
| window.location.href = redirect; | |
| } | |
| openInInstagram(); |
This file contains hidden or 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
| // ==UserScript== | |
| // @name Open X(Twitter) App Live Container | |
| // @version 1.0.0 | |
| // @author nathandaven | |
| // @match https://x.com/* | |
| // @downloadURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-twitter-live-container.user.js | |
| // @updateURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-twitter-live-container.user.js | |
| // @homepage https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae | |
| // ==/UserScript== | |
| // need to encode the string to base64 for live container link to work | |
| function utf8_to_b64(str) { | |
| return window.btoa(unescape(encodeURIComponent(str))); | |
| } | |
| function openInTwitterX() { | |
| const currentPath = window.location.pathname; | |
| const currentSearch = window.location.search; | |
| const timelinePaths = [ | |
| "/home", | |
| "/i/communitynotes", | |
| "/i/verified-orgs-signup", | |
| ]; | |
| const includePaths = ["/list"]; | |
| if ( | |
| currentPath === "/i/timeline" || | |
| currentPath.startsWith("/notifications") | |
| ) { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://mentions"); | |
| } else if (currentPath === "/i/grok") { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://grok"); | |
| } else if ( | |
| timelinePaths.some((path) => currentPath.startsWith(path)) || | |
| includePaths.some((path) => currentPath.includes(path)) | |
| ) { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://timeline"); | |
| } else if (currentPath === "/messages") { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://messages"); | |
| } else if (currentPath.startsWith("/messages/")) { | |
| const conversationId = currentPath.match(/\/messages\/([^/]+)/)[1]; | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`twitter://messages?id=${conversationId}`); | |
| } else if (currentPath.match(/\/status\/\d+$/)) { | |
| const statusId = currentPath.match(/\/status\/(\d+)/)[1]; | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`twitter://status?id=${statusId}`); | |
| } else if ( | |
| currentPath === "/compose/tweet" || | |
| currentPath === "/compose/post" | |
| ) { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64("twitter://post?message"); | |
| } else if ( | |
| currentPath === "/intent/tweet" || | |
| currentPath === "/intent/post" | |
| ) { | |
| // 'text=', 'url=', 'hashtags=' を取り除き、hashtags を %23 に置換 | |
| const param = currentSearch | |
| .replace("?text=", "") // 'text=' を取り除く | |
| .replace("&url=", "") // 'url=' を取り除く | |
| .replace("&hashtags=", "%23"); // 'hashtags=' を %23 に置換 | |
| // messageUrl を生成 | |
| const messageUrl = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`twitter://post?message=${param}`); | |
| // 結果を表示して、リンク先にリダイレクト | |
| alert(messageUrl); | |
| window.location.href = messageUrl; | |
| } else if (currentPath === "/explore") { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://explore"); | |
| } else if (currentPath === "/search" && currentSearch.includes("?q=")) { | |
| const searchTerm = currentSearch.match(/q=(.*?)&/)[1]; | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`twitter://search?query=${searchTerm}`); | |
| } else if (currentPath.startsWith("/i/bookmarks")) { | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + utf8_to_b64("twitter://bookmarks"); | |
| } else if (currentPath.includes("/communities")) { | |
| const communityIdMatch = currentPath.match(/\/communities\/([^/]+)/); | |
| const communityId = communityIdMatch ? communityIdMatch[1] : ""; | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64(`twitter://communities/${communityId}`); | |
| } else if (currentPath.startsWith("/") && currentPath != "/oauth/authorize") { | |
| const screenName = currentPath.match(/\/([^/]+)/)[1]; | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64( | |
| `twitter://user?screen_name=${encodeURIComponent(screenName)}` | |
| ); | |
| } | |
| } | |
| openInTwitterX(); |
This file contains hidden or 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
| // ==UserScript== | |
| // @name Open in Youtube Live Container | |
| // @version 1.0.0 | |
| // @author nathandaven | |
| // @match *://*.youtube.com/* | |
| // @downloadURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-youtube-live-container.user.js | |
| // @updateURL https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae/raw/62f5aa9d52998135346bc622244a66879becc6d2/open-in-youtube-live-container.user.js | |
| // @homepage https://gist.github.com/nathandaven/76fd9c1e9e7c30eaea29003120acb4ae | |
| // ==/UserScript== | |
| // need to encode the string to base64 for live container link to work | |
| function utf8_to_b64(str) { | |
| return window.btoa(unescape(encodeURIComponent(str))); | |
| } | |
| function openInYoutube() { | |
| if (window.self !== window.top) return; // iframe | |
| if (window.location.pathname === "/redirect") return; // Opening link in browser from app | |
| window.location.href = | |
| `livecontainer://open-web-page?url=` + | |
| utf8_to_b64( | |
| `youtube://${window.location.pathname.slice(1)}${window.location.search}${ | |
| window.location.hash | |
| }` | |
| ); | |
| } | |
| openInYoutube(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment