mirror of
https://github.com/wassname/talk.git
synced 2026-07-15 11:26:58 +08:00
[CORL-181] Comment Count Injection (#2581)
* feat: inject comment counts * fix: tests * feat: integrate stream embed with coral counts * chore: refactor constants * test: test for count bundle * test: test live comment count integration with stream embed * feat: use defer * fix: snapshot * feat: auto add count.js in when calling Coral.createStreamEmbed * fix: tests * fix: rm duplicate test * chore: remove unuse file
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* getCurrentScriptOrigin will try to find the script origin.
|
||||
* For legacy browsers a fallbackIdentifier is required.
|
||||
*
|
||||
* @argument fallbackID id attached to a script tag to get its origin from for legacy browsrs.
|
||||
*/
|
||||
function getCurrentScriptOrigin(fallbackID?: string) {
|
||||
// Find current script (modern browsers).
|
||||
let script = document.currentScript as HTMLScriptElement | null;
|
||||
|
||||
if (!script && fallbackID) {
|
||||
// Find script tag with `fallbackIdentifier` as its id.
|
||||
script = document.getElementById(fallbackID) as HTMLScriptElement | null;
|
||||
if (!script) {
|
||||
// Find script tag with `fallbackIdentifier` as its className.
|
||||
script = document.querySelector(
|
||||
`.${fallbackID}`
|
||||
) as HTMLScriptElement | null;
|
||||
}
|
||||
}
|
||||
if (!script) {
|
||||
throw new Error("Current script not found");
|
||||
}
|
||||
return new URL(script.src).origin;
|
||||
}
|
||||
|
||||
export default getCurrentScriptOrigin;
|
||||
Reference in New Issue
Block a user