Skip to content

Commit

Permalink
deploy: update dist v1.9.96
Browse files Browse the repository at this point in the history
  • Loading branch information
Atlassian Bamboo committed Nov 15, 2023
1 parent 3556089 commit 804a596
Show file tree
Hide file tree
Showing 6 changed files with 371 additions and 33 deletions.
2 changes: 1 addition & 1 deletion dist/build.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.9.91
version=1.9.96
2 changes: 1 addition & 1 deletion dist/redirects.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# AdGuard Scriptlets (Redirects Source)
# Version 1.9.91
# Version 1.9.96
#
- title: 1x1-transparent.gif
added: v1.0.4
Expand Down
8 changes: 4 additions & 4 deletions dist/scriptlets.corelibs.json

Large diffs are not rendered by default.

184 changes: 172 additions & 12 deletions dist/scriptlets.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

/**
* AdGuard Scriptlets
* Version 1.9.91
* Version 1.9.96
*/

(function () {
Expand Down Expand Up @@ -2026,7 +2026,17 @@
*/
var removeStorageItem = function removeStorageItem(source, storage, key) {
try {
storage.removeItem(key);
if (key.startsWith('/') && (key.endsWith('/') || key.endsWith('/i')) && isValidStrPattern(key)) {
var regExpKey = toRegExp(key);
var storageKeys = Object.keys(storage);
storageKeys.forEach(function (storageKey) {
if (regExpKey.test(storageKey)) {
storage.removeItem(storageKey);
}
});
} else {
storage.removeItem(key);
}
} catch (e) {
var message = "Unable to remove storage item due to: ".concat(e.message);
logMessage(source, message);
Expand Down Expand Up @@ -3724,7 +3734,7 @@
* ### Syntax
*
* ```text
* example.org#%#//scriptlet('set-constant', property, value[, stack])
* example.org#%#//scriptlet('set-constant', property, value[, stack,[ valueWrapper[, setProxyTrap]]])
* ```
*
* - `property` — required, path to a property (joined with `.` if needed). The property must be attached to `window`.
Expand Down Expand Up @@ -3755,6 +3765,7 @@
* - `asCallback` – function returning callback, that would return value
* - `asResolved` – Promise that would resolve with value
* - `asRejected` – Promise that would reject with value
* - `setProxyTrap` – optional, boolean, if set to true, proxy trap will be set on the object
*
* ### Examples
*
Expand Down Expand Up @@ -3794,12 +3805,22 @@
* ✔ document.fifth.catch((reason) => reason === 42) // promise rejects with specified number
* ```
*
* ```adblock
* ! Any access to `window.foo.bar` will return `false` and the proxy trap will be set on the `foo` object
* ! It may be required in the case when `foo` object is overwritten by website script
* ! Related to this issue - https://github.com/AdguardTeam/Scriptlets/issues/330
* example.org#%#//scriptlet('set-constant', 'foo.bar', 'false', '', '', 'true')
*
* ✔ window.foo.bar === false
* ```
*
* @added v1.0.4.
*/
/* eslint-enable max-len */
function setConstant$1(source, property, value) {
var stack = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
var valueWrapper = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : '';
var setProxyTrap = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
var uboAliases = ['set-constant.js', 'ubo-set-constant.js', 'set.js', 'ubo-set.js', 'ubo-set-constant', 'ubo-set'];

/**
Expand Down Expand Up @@ -3961,7 +3982,7 @@
// Get properties which should be checked and remove first one
// because it's current object
var propertiesToCheck = property.split('.').slice(1);
if (!isProxyTrapSet) {
if (setProxyTrap && !isProxyTrapSet) {
isProxyTrapSet = true;
a = new Proxy(a, {
get: function get(target, propertyKey, val) {
Expand Down Expand Up @@ -6532,7 +6553,8 @@
* example.com#%#//scriptlet('set-local-storage-item', 'key', 'value')
* ```
*
* - `key` — required, key name to be set.
* - `key` — required, key name to be set. Should be a string for setting,
* but it also can be a regular expression for removing items from localStorage.
* - `value` — required, key value; possible values:
* - positive decimal integer `<= 32767`
* - one of the predefined constants in any case variation:
Expand All @@ -6558,6 +6580,9 @@
*
* ! Removes the item with key 'foo' from local storage
* example.org#%#//scriptlet('set-local-storage-item', 'foo', '$remove$')
*
* ! Removes from local storage all items whose key matches the regular expression `/mp_.*_mixpanel/`
* example.org#%#//scriptlet('set-local-storage-item', '/mp_.*_mixpanel/', '$remove$')
* ```
*
* @added v1.4.3.
Expand Down Expand Up @@ -6588,7 +6613,9 @@
setLocalStorageItem$1.names = ['set-local-storage-item',
// aliases are needed for matching the related scriptlet converted into our syntax
'set-local-storage-item.js', 'ubo-set-local-storage-item.js', 'ubo-set-local-storage-item'];
setLocalStorageItem$1.injections = [hit, logMessage, nativeIsNaN, setStorageItem, removeStorageItem, getLimitedStorageItemValue];
setLocalStorageItem$1.injections = [hit, logMessage, nativeIsNaN, setStorageItem, removeStorageItem, getLimitedStorageItemValue,
// following helpers are needed for helpers above
isValidStrPattern, toRegExp, escapeRegExp];

/* eslint-disable max-len */
/**
Expand All @@ -6609,7 +6636,8 @@
* example.com#%#//scriptlet('set-session-storage-item', 'key', 'value')
* ```
*
* - `key` — required, key name to be set.
* - `key` — required, key name to be set. Should be a string for setting,
* but it also can be a regular expression for removing items from localStorage.
* - `value` — required, key value; possible values:
* - positive decimal integer `<= 32767`
* - one of the predefined constants in any case variation:
Expand All @@ -6635,6 +6663,9 @@
*
* ! Removes the item with key 'foo' from session storage
* example.org#%#//scriptlet('set-session-storage-item', 'foo', '$remove$')
*
* ! Removes from session storage all items whose key matches the regular expression `/mp_.*_mixpanel/`
* example.org#%#//scriptlet('set-session-storage-item', '/mp_.*_mixpanel/', '$remove$')
* ```
*
* @added v1.4.3.
Expand Down Expand Up @@ -6665,7 +6696,9 @@
setSessionStorageItem$1.names = ['set-session-storage-item',
// aliases are needed for matching the related scriptlet converted into our syntax
'set-session-storage-item.js', 'ubo-set-session-storage-item.js', 'ubo-set-session-storage-item'];
setSessionStorageItem$1.injections = [hit, logMessage, nativeIsNaN, setStorageItem, removeStorageItem, getLimitedStorageItemValue];
setSessionStorageItem$1.injections = [hit, logMessage, nativeIsNaN, setStorageItem, removeStorageItem, getLimitedStorageItemValue,
// following helpers are needed for helpers above
isValidStrPattern, toRegExp, escapeRegExp];

/* eslint-disable max-len */
/**
Expand Down Expand Up @@ -9922,7 +9955,7 @@
* example.org#%#//scriptlet('trusted-prune-inbound-object', 'JSON.stringify', '', 'bar', '')
* ```
*
* @added unknown.
* @added v1.9.91.
*/
/* eslint-enable max-len */
function trustedPruneInboundObject$1(source, functionName, propsToRemove, requiredInitialProps) {
Expand Down Expand Up @@ -24458,6 +24491,7 @@
function setConstant(source, property, value) {
var stack = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "";
var valueWrapper = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : "";
var setProxyTrap = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
var uboAliases = ["set-constant.js", "ubo-set-constant.js", "set.js", "ubo-set.js", "ubo-set-constant", "ubo-set"];
if (uboAliases.includes(source.name)) {
if (stack.length !== 1 && !getNumberFromString(stack)) {
Expand Down Expand Up @@ -24579,7 +24613,7 @@
}
if (a instanceof Object) {
var propertiesToCheck = property.split(".").slice(1);
if (!isProxyTrapSet) {
if (setProxyTrap && !isProxyTrapSet) {
isProxyTrapSet = true;
a = new Proxy(a, {
get: function get(target, propertyKey, val) {
Expand Down Expand Up @@ -25258,7 +25292,17 @@
}
function removeStorageItem(source, storage, key) {
try {
storage.removeItem(key);
if (key.startsWith("/") && (key.endsWith("/") || key.endsWith("/i")) && isValidStrPattern(key)) {
var regExpKey = toRegExp(key);
var storageKeys = Object.keys(storage);
storageKeys.forEach(function (storageKey) {
if (regExpKey.test(storageKey)) {
storage.removeItem(storageKey);
}
});
} else {
storage.removeItem(key);
}
} catch (e) {
var message = "Unable to remove storage item due to: ".concat(e.message);
logMessage(source, message);
Expand Down Expand Up @@ -25291,6 +25335,59 @@
}
return validValue;
}
function isValidStrPattern(input) {
var FORWARD_SLASH = "/";
var str = escapeRegExp(input);
if (input[0] === FORWARD_SLASH && input[input.length - 1] === FORWARD_SLASH) {
str = input.slice(1, -1);
}
var isValid;
try {
isValid = new RegExp(str);
isValid = true;
} catch (e) {
isValid = false;
}
return isValid;
}
function toRegExp() {
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var DEFAULT_VALUE = ".?";
var FORWARD_SLASH = "/";
if (input === "") {
return new RegExp(DEFAULT_VALUE);
}
var delimiterIndex = input.lastIndexOf(FORWARD_SLASH);
var flagsPart = input.substring(delimiterIndex + 1);
var regExpPart = input.substring(0, delimiterIndex + 1);
var isValidRegExpFlag = function isValidRegExpFlag(flag) {
if (!flag) {
return false;
}
try {
new RegExp("", flag);
return true;
} catch (ex) {
return false;
}
};
var getRegExpFlags = function getRegExpFlags(regExpStr, flagsStr) {
if (regExpStr.startsWith(FORWARD_SLASH) && regExpStr.endsWith(FORWARD_SLASH) && !regExpStr.endsWith("\\/") && isValidRegExpFlag(flagsStr)) {
return flagsStr;
}
return "";
};
var flags = getRegExpFlags(regExpPart, flagsPart);
if (input.startsWith(FORWARD_SLASH) && input.endsWith(FORWARD_SLASH) || flags) {
var regExpInput = flags ? regExpPart : input;
return new RegExp(regExpInput.slice(1, -1), flags);
}
var escaped = input.replace(/\\'/g, "'").replace(/\\"/g, '"').replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(escaped);
}
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
var updatedArgs = args ? [].concat(source).concat(args) : [source];
try {
setLocalStorageItem.apply(this, updatedArgs);
Expand Down Expand Up @@ -25435,7 +25532,17 @@
}
function removeStorageItem(source, storage, key) {
try {
storage.removeItem(key);
if (key.startsWith("/") && (key.endsWith("/") || key.endsWith("/i")) && isValidStrPattern(key)) {
var regExpKey = toRegExp(key);
var storageKeys = Object.keys(storage);
storageKeys.forEach(function (storageKey) {
if (regExpKey.test(storageKey)) {
storage.removeItem(storageKey);
}
});
} else {
storage.removeItem(key);
}
} catch (e) {
var message = "Unable to remove storage item due to: ".concat(e.message);
logMessage(source, message);
Expand Down Expand Up @@ -25468,6 +25575,59 @@
}
return validValue;
}
function isValidStrPattern(input) {
var FORWARD_SLASH = "/";
var str = escapeRegExp(input);
if (input[0] === FORWARD_SLASH && input[input.length - 1] === FORWARD_SLASH) {
str = input.slice(1, -1);
}
var isValid;
try {
isValid = new RegExp(str);
isValid = true;
} catch (e) {
isValid = false;
}
return isValid;
}
function toRegExp() {
var input = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
var DEFAULT_VALUE = ".?";
var FORWARD_SLASH = "/";
if (input === "") {
return new RegExp(DEFAULT_VALUE);
}
var delimiterIndex = input.lastIndexOf(FORWARD_SLASH);
var flagsPart = input.substring(delimiterIndex + 1);
var regExpPart = input.substring(0, delimiterIndex + 1);
var isValidRegExpFlag = function isValidRegExpFlag(flag) {
if (!flag) {
return false;
}
try {
new RegExp("", flag);
return true;
} catch (ex) {
return false;
}
};
var getRegExpFlags = function getRegExpFlags(regExpStr, flagsStr) {
if (regExpStr.startsWith(FORWARD_SLASH) && regExpStr.endsWith(FORWARD_SLASH) && !regExpStr.endsWith("\\/") && isValidRegExpFlag(flagsStr)) {
return flagsStr;
}
return "";
};
var flags = getRegExpFlags(regExpPart, flagsPart);
if (input.startsWith(FORWARD_SLASH) && input.endsWith(FORWARD_SLASH) || flags) {
var regExpInput = flags ? regExpPart : input;
return new RegExp(regExpInput.slice(1, -1), flags);
}
var escaped = input.replace(/\\'/g, "'").replace(/\\"/g, '"').replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
return new RegExp(escaped);
}
function escapeRegExp(str) {
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
}
var updatedArgs = args ? [].concat(source).concat(args) : [source];
try {
setSessionStorageItem.apply(this, updatedArgs);
Expand Down
Loading

0 comments on commit 804a596

Please sign in to comment.