Skip to content

Commit

Permalink
1.5.76 : Fixed misc tags frameset|frame that could be removed from bo…
Browse files Browse the repository at this point in the history
…dy and tested multiple tags that could cause issues, found none
  • Loading branch information
ThomazPom committed Oct 27, 2024
1 parent 208dd81 commit f652779
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 4 deletions.
8 changes: 7 additions & 1 deletion background.js
Original file line number Diff line number Diff line change
Expand Up @@ -3095,7 +3095,13 @@ const dark_object = {
return str;
}

str = str.protect_simple(/\b(head|html|body)\b/gi, "ud-tag-ptd-$1"); // use word boundaries to avoid matching tags like "headings" or tbody or texts like innerHTML

str = str.protect_simple(/\b(head|html|body|frameset|frame)\b/gi, "ud-tag-ptd-$1"
// use word boundaries to avoid matching tags like "headings" or tbody or texts like innerHTML
// Frame and frameset are obsolete, but there were meant to be in head, and will be removed from body, they need to be protected

);


let parsedDocument = uDark.createDocumentFromHtml("<body>"+str+"</body>"
/* Re encapsulate str into a <body> is not an overkill : Exists something called unsafeHTML clid binding. I did not understood what it is, but it needs a body tag for proper parsing*/
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "UltimaDark",
"version": "1.5.75",
"version": "1.5.76",
"description": "The extension uses agressive techniques to get a dark mode everywhere on internet\nThis is still highly experimental so it can also ruin your internet experience",
"homepage_url": "https://github.com/ThomazPom/Moz-Ext-UltimaDark",
"icons": {
Expand Down
105 changes: 105 additions & 0 deletions other-tools-and-tests/quirks/misc_tags_removed_from_parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Define the testTag function
function testTag(tagHtml) {
// Build HTML strings for testing the tag in <body> and <head>
const htmlInBody = `
<html>
<head><title>Test Document</title></head>
<body>
${tagHtml}
</body>
</html>
`;

const htmlInHead = `
<html>
<head>
${tagHtml}
</head>
<body>
<p>This is body content.</p>
</body>
</html>
`;

// Parse the HTML strings
const parser = new DOMParser();

// Parse the HTML with the tag in <body>
const docBody = parser.parseFromString(htmlInBody, "text/html");
const initialTagsInBody = Array.from(tagHtml.matchAll(/<([a-z]+)[\s>]/gi)).map(match => match[1]);
const remainingTagsInBody = Array.from(docBody.body.querySelectorAll("*")).map(el => el.tagName.toLowerCase());
const removedTagsInBody = initialTagsInBody.filter(tag => !remainingTagsInBody.includes(tag));

// Parse the HTML with the tag in <head>
const docHead = parser.parseFromString(htmlInHead, "text/html");
const initialTagsInHead = Array.from(tagHtml.matchAll(/<([a-z]+)[\s>]/gi)).map(match => match[1]);
const remainingTagsInHead = Array.from(docHead.head.querySelectorAll("*")).map(el => el.tagName.toLowerCase());
const removedTagsInHead = initialTagsInHead.filter(tag => !remainingTagsInHead.includes(tag));

// Log results for both <body> and <head> placements
console.log("Testing tag:", tagHtml);

if (removedTagsInBody.length > 0) {
console.warn("In <body> - Elements removed:", Array.from(new Set(removedTagsInBody)));
console.log("o",htmlInBody);
console.log("p",docBody.documentElement.outerHTML)
console.log("Parsed:",docBody)
} else {
console.log("In <body> - Elements kept:", remainingTagsInBody);
}

console.log("In <head> - Elements removed:", Array.from(new Set(removedTagsInHead)));
console.log("In <head> - Elements kept:", remainingTagsInHead);
console.log("-------------------------------------------------------");
}

// Test multiple tags by calling testTag with various HTML snippets

// Root and metadata tags
testTag('<meta charset="UTF-8">');
testTag('<link rel="stylesheet" href="style.css">');
testTag('<base href="/">');
testTag('<title>Test Document</title>');

// Frameset and frames
testTag('<frameset rows="50%,50%"><frame src="frame1.html"><frame src="frame2.html"></frameset>');

// Deprecated and special behavior tags
testTag('<center>This is centered text</center>');
testTag('<font color="red">This is red text using font tag</font>');
testTag('<applet code="MyApplet.class"></applet>');
testTag('<strike>This text is struck through</strike>');
testTag('<u>This text is underlined</u>');
testTag('<big>This text is big</big>');
testTag('<blink>This text blinks</blink>');
testTag('<marquee>Scrolling Text in Marquee</marquee>');
testTag('<dir><li>Item 1</li><li>Item 2</li></dir>');

// Media embedding and scripting tags
testTag('<script>alert("This is a script");</script>');
testTag('<noscript>JavaScript is disabled</noscript>');
testTag('<embed src="media.mp3">');
testTag('<object data="data.pdf" type="application/pdf"></object>');
testTag('<param name="autoplay" value="true">');

// MathML and SVG tags
testTag('<math><mrow><mi>a</mi><mo>=</mo><mi>b</mi></mrow></math>');
testTag('<svg width="100" height="100"><circle cx="50" cy="50" r="40" /></svg>');

// Web components and custom elements
testTag('<template><p>Template content</p></template>');
testTag('<slot name="slot-content"></slot>');
testTag('<custom-element></custom-element>');

// HTML5 interactive and miscellaneous tags
testTag('<dialog open>This is a dialog</dialog>');
testTag('<menu label="Options"><menuitem label="Save"></menuitem><menuitem label="Load"></menuitem></menu>');

// Obsolete formatting tags
testTag('<isindex prompt="Search:">');
testTag('<listing>This is a listing tag</listing>');
testTag('<xmp>This is an xmp tag</xmp>');
testTag('<plaintext>This tag turns everything into plain text</plaintext>');
testTag('<tt>This is teletype text</tt>');
testTag('<spacer size="50">');

5 changes: 3 additions & 2 deletions uDarkEncoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,6 @@ testURLCharset= async (url,charset)=>{
{
console.error("Decoding/Encoding Mismatch");

console.log("Decoded",decoder.decode(data),data.length);
console.log("Original",decoded);
console.log("Decoded",myStringVersion);
}
Expand All @@ -657,4 +656,6 @@ testURLCharset= async (url,charset)=>{
}
// z("http://charset.7jp.net/mojibake.html","shift_jis");
// testURLCharset("http://charset.7jp.net/sjis.html","shift_jis");
// testURLCharset("http://charset.7jp.net/ascii.cgi","shift_jis");
// testURLCharset("http://charset.7jp.net/ascii.cgi","shift_jis");
// testURLCharset("http://charset.7jp.net/ascii.cgi","shift_jis");
// testURLCharset("https://www.hyperhosting.gr/grdomains/","ISO-8859-7");

0 comments on commit f652779

Please sign in to comment.