@glitchr/transparent 1.0.57 → 1.0.58

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glitchr/transparent",
3
- "version": "1.0.57",
3
+ "version": "1.0.58",
4
4
  "description": "Transparent SPA Application",
5
5
  "main": "src/index.js",
6
6
  "access": "public",
@@ -179,7 +179,8 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
179
179
  "smoothscroll_duration": "200ms",
180
180
  "smoothscroll_speed" : 0,
181
181
  "smoothscroll_easing" : "swing",
182
- "exceptions": []
182
+ "exceptions": [],
183
+ "headlock": [],
183
184
  };
184
185
 
185
186
  const State = Transparent.state = {
@@ -1223,17 +1224,59 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1223
1224
 
1224
1225
  activeInRemainingTime = activeInRemainingTime - (Date.now() - activeInTime);
1225
1226
  setTimeout(function() {
1226
-
1227
+
1227
1228
  // Transfert attributes
1228
1229
  Transparent.transferAttributes(dom);
1230
+ function isHeadLocked(el) {
1231
+
1232
+ // only for <script>, <link>, etc. that carry a URL
1233
+ const raw = (el.getAttribute("src") || el.getAttribute("href") || "").trim();
1234
+ if (!raw) return false;
1235
+
1236
+ // normalize to an absolute href string
1237
+ let href = raw;
1238
+ try { href = new URL(raw, location.href).href; } catch {}
1239
+
1240
+ return Settings.headlock.some((rule) => {
1241
+ if (rule instanceof RegExp) {
1242
+ return rule.test(href); // <= test against the string, not url.href
1243
+ }
1244
+
1245
+ if (typeof rule === "string") {
1246
+
1247
+ if (rule.includes("*")) {
1248
+ const pattern = "^" + rule
1249
+ .replace(/[.+^${}()|[\]\\]/g, "\\$&")
1250
+ .replace(/\*/g, ".*") + "$";
1251
+ return new RegExp(pattern).test(href);
1252
+ }
1253
+
1254
+ // No wildcard: treat as origin/prefix
1255
+ // If rule parses as a URL, compare origins; otherwise do simple prefix
1256
+ try {
1257
+ const r = new URL(rule, location.href);
1258
+ const u = new URL(href);
1259
+ // Match same origin, OR rule is a full URL prefix of href
1260
+ return (u.origin === r.origin) || href.startsWith(r.href);
1261
+ } catch {
1262
+ return href.startsWith(rule);
1263
+ }
1264
+ }
1265
+
1266
+ return false;
1267
+ });
1268
+ }
1229
1269
 
1230
1270
  // Replace head..
1231
1271
  var head = $(dom).find("head");
1232
1272
  $("head").children().each(function() {
1233
1273
 
1234
1274
  var el = this;
1275
+ if (isHeadLocked(el)) {
1276
+ return;
1277
+ }
1278
+
1235
1279
  var found = false;
1236
-
1237
1280
  head.children().each(function() {
1238
1281
 
1239
1282
  found = this.isEqualNode(el);
@@ -1251,7 +1294,6 @@ jQuery.event.special.mousewheel = { setup: function( _, ns, handle ) { this.addE
1251
1294
  $("head").children().each(function() { found |= this.isEqualNode(el); });
1252
1295
  if(!found) {
1253
1296
 
1254
-
1255
1297
  if(this.tagName != "SCRIPT" || Settings["global_code"] == true) {
1256
1298
 
1257
1299
  $("head").append(this.cloneNode(true));