From 348435a95f5000939a6b67ec101b996f654b6b26 Mon Sep 17 00:00:00 2001 From: piquark6046 Date: Sat, 2 Dec 2023 13:20:54 +0000 Subject: [PATCH] fix: proportionof the PowerLink container is high to be detected --- NamuLink.user.js | 18 ++++++++++-------- NamuLink.user.ts | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/NamuLink.user.js b/NamuLink.user.js index c24c60d..11a469a 100644 --- a/NamuLink.user.js +++ b/NamuLink.user.js @@ -8,7 +8,7 @@ // @downloadURL https://cdn.jsdelivr.net/gh/List-KR/NamuLink@latest/NamuLink.user.js // @license MIT // -// @version 2.1.8 +// @version 2.1.9 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* @@ -64,7 +64,7 @@ return Array.from(element.querySelectorAll('*')).filter(function (AllElement) { return AllElement instanceof HTMLElement; }); } // The following proxy handles PowerLink advertisement that is loaded after the initial loading. - for (let BitArrayObj of [Uint8ClampedArray, Int8Array, Uint8Array]) { + for (let BitArrayObj of [win.Uint8ClampedArray, win.Int8Array, win.Uint8Array]) { // Prepare function for Uint8ClampedArray, Int8Array and Uint8Array. function BitArrayProxy(target, thisArg, argumentsList) { let OriginalValue = Reflect.apply(target, thisArg, argumentsList); @@ -114,9 +114,10 @@ try { let DivTableElements = Array.from(document.querySelectorAll('div,table')); let PowerLinkContainers = DivTableElements.filter(function (element) { - return 1.5 < (element.offsetWidth / element.offsetHeight) && 2.5 > (element.offsetWidth / element.offsetHeight) && - parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 15 && - !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? ''); })); + return parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 15 && + Children(element).some(function (Child) { return (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/${Child.getAttribute('title') ?? ''}`) || (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/사용자:${Child.getAttribute('title') ?? ''}`); }) && + !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? ''); })) && + !(Children(element).some(function (Child) { return (Child.getAttribute('href') ?? '').startsWith('#rfn-'); })); }); HideElementsImportant(PowerLinkContainers); } @@ -131,9 +132,10 @@ try { let DivTableElements = Array.from(document.querySelectorAll('div,table')); let PowerLinkContainers = DivTableElements.filter(function (element) { - return 1.5 < (element.offsetWidth / element.offsetHeight) && - parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 25 && - !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? ''); })); + return parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 25 && + Children(element).some(function (Child) { return (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/${Child.getAttribute('title') ?? ''}`) || (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/사용자:${Child.getAttribute('title') ?? ''}`); }) && + !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? ''); })) && + !(Children(element).some(function (Child) { return (Child.getAttribute('href') ?? '').startsWith('#rfn-'); })); }); HideElementsImportant(PowerLinkContainers); } diff --git a/NamuLink.user.ts b/NamuLink.user.ts index 5dc7d5e..1607e1e 100644 --- a/NamuLink.user.ts +++ b/NamuLink.user.ts @@ -8,7 +8,7 @@ // @downloadURL https://cdn.jsdelivr.net/gh/List-KR/NamuLink@latest/NamuLink.user.js // @license MIT // -// @version 2.1.8 +// @version 2.1.9 // @author PiQuark6046 and contributors // // @match https://namu.wiki/* @@ -71,7 +71,7 @@ declare const unsafeWindow: unsafeWindow } // The following proxy handles PowerLink advertisement that is loaded after the initial loading. - for (let BitArrayObj of [Uint8ClampedArray, Int8Array, Uint8Array]) { + for (let BitArrayObj of [win.Uint8ClampedArray, win.Int8Array, win.Uint8Array]) { // Prepare function for Uint8ClampedArray, Int8Array and Uint8Array. function BitArrayProxy (target, thisArg, argumentsList) { let OriginalValue:Uint16Array | Int8Array | Uint8Array = Reflect.apply(target, thisArg, argumentsList) @@ -125,9 +125,10 @@ declare const unsafeWindow: unsafeWindow try { let DivTableElements = Array.from(document.querySelectorAll('div,table')) as Array let PowerLinkContainers: Array = DivTableElements.filter(function(element) { - return 1.5 < (element.offsetWidth / element.offsetHeight) && 2.5 > (element.offsetWidth / element.offsetHeight) && - parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 15 && - !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? '') })) + return parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 15 && + Children(element).some(function (Child) { return (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/${Child.getAttribute('title') ?? ''}`) || (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/사용자:${Child.getAttribute('title') ?? ''}`)}) && + !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? '') })) && + !(Children(element).some(function (Child) { return (Child.getAttribute('href') ?? '').startsWith('#rfn-') })) }) HideElementsImportant(PowerLinkContainers) } catch (error) { @@ -140,9 +141,10 @@ declare const unsafeWindow: unsafeWindow try { let DivTableElements = Array.from(document.querySelectorAll('div,table')) as Array let PowerLinkContainers: Array = DivTableElements.filter(function(element) { - return 1.5 < (element.offsetWidth / element.offsetHeight) && - parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 25 && - !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? '') })) + return parseInt(getComputedStyle(element).getPropertyValue('margin-top').replace(/px$/, '')) > 25 && + Children(element).some(function (Child) { return (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/${Child.getAttribute('title') ?? ''}`) || (decodeURIComponent(Child.getAttribute('href') ?? '')).startsWith(`/w/사용자:${Child.getAttribute('title') ?? ''}`)}) && + !(Children(element).some(function (Child) { return (Child.getAttribute('loading') ?? '') === 'lazy' || /^jump\//.test(Child.getAttribute('data-doc') ?? '') })) && + !(Children(element).some(function (Child) { return (Child.getAttribute('href') ?? '').startsWith('#rfn-') })) }) HideElementsImportant(PowerLinkContainers) } catch (error) {