mirror of
https://github.com/ankitects/anki.git
synced 2025-09-22 16:02:23 -04:00
Switch to iterables for elem.style and elem.attributes
This commit is contained in:
parent
a4921a36dd
commit
47d26126e7
3 changed files with 13 additions and 11 deletions
|
@ -11,7 +11,13 @@ declare interface String {
|
||||||
|
|
||||||
/* kept for compatibility with add-ons */
|
/* kept for compatibility with add-ons */
|
||||||
String.prototype.format = function (...args: string[]): string {
|
String.prototype.format = function (...args: string[]): string {
|
||||||
return this.replace(/\{\d+\}/g, (m) => args[m.match(/\d+/)]);
|
return this.replace(/\{\d+\}/g, (m: string): void => {
|
||||||
|
const match = m.match(/\d+/)
|
||||||
|
|
||||||
|
return match
|
||||||
|
? args[match[0]]
|
||||||
|
: "";
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
function setFGButton(col: string): void {
|
function setFGButton(col: string): void {
|
||||||
|
@ -518,8 +524,7 @@ let isNightMode = function (): boolean {
|
||||||
|
|
||||||
let filterExternalSpan = function (elem: HTMLElement) {
|
let filterExternalSpan = function (elem: HTMLElement) {
|
||||||
// filter out attributes
|
// filter out attributes
|
||||||
for (let i = 0; i < elem.attributes.length; i++) {
|
for (const attr of [...elem.attributes]) {
|
||||||
const attr = elem.attributes.item(i);
|
|
||||||
const attrName = attr.name.toUpperCase();
|
const attrName = attr.name.toUpperCase();
|
||||||
|
|
||||||
if (attrName !== "STYLE") {
|
if (attrName !== "STYLE") {
|
||||||
|
@ -528,8 +533,7 @@ let filterExternalSpan = function (elem: HTMLElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// filter styling
|
// filter styling
|
||||||
for (let i = 0; i < elem.style.length; i++) {
|
for (const name of [...elem.style]) {
|
||||||
const name = elem.style.item(i);
|
|
||||||
const value = elem.style.getPropertyValue(name);
|
const value = elem.style.getPropertyValue(name);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
@ -575,8 +579,7 @@ let filterNode = function (node: Node, extendedMode: boolean): void {
|
||||||
|
|
||||||
// descend first, and take a copy of the child nodes as the loop will skip
|
// descend first, and take a copy of the child nodes as the loop will skip
|
||||||
// elements due to node modifications otherwise
|
// elements due to node modifications otherwise
|
||||||
for (let i = 0; i < node.children.length; i++) {
|
for (const child of [...node.children]) {
|
||||||
const child = node.children[i];
|
|
||||||
filterNode(child, extendedMode);
|
filterNode(child, extendedMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -600,8 +603,7 @@ let filterNode = function (node: Node, extendedMode: boolean): void {
|
||||||
tag(node);
|
tag(node);
|
||||||
} else {
|
} else {
|
||||||
// allowed, filter out attributes
|
// allowed, filter out attributes
|
||||||
for (let i = 0; i < node.attributes.length; i++) {
|
for (const attr of [...node.attributes]) {
|
||||||
const attr = node.attributes.item(i);
|
|
||||||
const attrName = attr.name.toUpperCase();
|
const attrName = attr.name.toUpperCase();
|
||||||
if (tag.attrs.indexOf(attrName) === -1) {
|
if (tag.attrs.indexOf(attrName) === -1) {
|
||||||
node.removeAttributeNode(attr);
|
node.removeAttributeNode(attr);
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "commonjs",
|
"module": "commonjs",
|
||||||
"lib": ["es6", "dom"],
|
"lib": ["es6", "dom", "dom.iterable"],
|
||||||
"strict": true,
|
"strict": true,
|
||||||
"noImplicitAny": false,
|
"noImplicitAny": false,
|
||||||
"strictNullChecks": false,
|
"strictNullChecks": false,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"target": "es6",
|
"target": "es6",
|
||||||
"module": "es6",
|
"module": "es6",
|
||||||
"lib": ["es2016", "es2019.array", "dom"],
|
"lib": ["es2016", "es2019.array", "dom", "dom.iterable"],
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
"anki/*": ["../bazel-bin/ts/lib/*"]
|
"anki/*": ["../bazel-bin/ts/lib/*"]
|
||||||
|
|
Loading…
Reference in a new issue