-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
14 additions
and
5 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
diff --git a/src/init-iife.js b/src/init-iife.js | ||
index 3c91c81..4600fc4 100644 | ||
index 3c91c81..0adeb19 100644 | ||
--- a/src/init-iife.js | ||
+++ b/src/init-iife.js | ||
@@ -1 +1,7 @@ | ||
@@ -1 +1,16 @@ | ||
-!function(){"use strict";async function e(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function t(){document.querySelector("body")?.addEventListener("click",(function(t){let n=t.target;for(;n;){if(n.matches("a")){const r=n;""!==r.href&&["http://","https://","mailto:","tel:"].some((e=>r.href.startsWith(e)))&&"_blank"===r.target&&(e("plugin:shell|open",{path:r.href}),t.preventDefault());break}n=n.parentElement}}))}"function"==typeof SuppressedError&&SuppressedError,"complete"===document.readyState||"interactive"===document.readyState?t():window.addEventListener("DOMContentLoaded",t,!0)}(); | ||
+const discordReg = /https?:\/\/(?:[a-z]+\.)?(?:discord\.com|discordapp\.com)(?:\/.*)?/g | ||
+ | ||
+function sameOrigin(a, b) { | ||
+ const uA = new URL(a) | ||
+ const uB = new URL(b) | ||
+ return uA.origin === uB.origin; | ||
+ const uA = new URL(stripDiscordSubdomain(a)) | ||
+ const uB = new URL(stripDiscordSubdomain(b)) | ||
+ return uA.origin === uB.origin | ||
+} | ||
+ | ||
+function stripDiscordSubdomain(link) { | ||
+ // If this isn't a discord link, just return the link | ||
+ if (!link.match(discordReg)) return link | ||
+ | ||
+ return link.replace(/canary\.|ptb\.|www\./g, '') | ||
+} | ||
+ | ||
+!function(){"use strict";async function e(e,t={},n){return window.__TAURI_INTERNALS__.invoke(e,t,n)}function t(){document.querySelector("body")?.addEventListener("click",(function(t){let n=t.target;for(;n;){if(n.matches("a")){const r=n;""!==r.href&&["http://","https://","mailto:","tel:"].some((e=>r.href.startsWith(e)))&&"_blank"===r.target&&!sameOrigin(r.href, window.location.href)&&(e("plugin:shell|open",{path:r.href}),t.preventDefault());break}n=n.parentElement}}),true)}"function"==typeof SuppressedError&&SuppressedError,"complete"===document.readyState||"interactive"===document.readyState?t():window.addEventListener("DOMContentLoaded",t,!0)}(); |