diff --git a/README.md b/README.md index 151f075..c423113 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Also, use this if you plan to use b4k's archive. - [Install 4chanX (recommended)](https://www.4chan-x.net/builds/4chan-X.user.js) - [Install JKCS (recommended)](https://git.coom.tech/araragi/JKCS/src/branch/master/README.md) -- Install the correct WebExtension for your Browser ([Firefox](https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.315.xpi) or Chrome-based (Down for "maintainance")) +- Install the correct WebExtension for your Browser ([Firefox](https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.320.xpi) or Chrome-based (Down for "maintainance")) For FF users, the extension is signed so you can just drag and drop it on your about:addons tab. diff --git a/chrome/dist/main.js b/chrome/dist/main.js index 09ea1b6..ddce403 100644 --- a/chrome/dist/main.js +++ b/chrome/dist/main.js @@ -73,7 +73,7 @@ var define_BUILD_VERSION_default; var init_define_BUILD_VERSION = __esm({ ""() { - define_BUILD_VERSION_default = [0, 315]; + define_BUILD_VERSION_default = [0, 320]; } }); @@ -10939,7 +10939,52 @@ settings.subscribe((b) => { csettings = b; }); + var generateUglyThumbnail = async (f) => { + const can = document.createElement("canvas"); + const [sw, sh] = [125, 125]; + const url = URL.createObjectURL(f); + let source; + let iw, ih; + if (f.type.startsWith("image")) { + const imgElem = document.createElement("img"); + imgElem.src = url; + await new Promise((_) => imgElem.onload = _); + [iw, ih] = [imgElem.naturalWidth, imgElem.naturalHeight]; + source = imgElem; + } else if (f.type.startsWith("video")) { + const vidElem = document.createElement("video"); + vidElem.src = url; + await new Promise((_) => vidElem.onloadedmetadata = _); + vidElem.currentTime = 0; + await new Promise((_) => vidElem.onloadeddata = _); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + [iw, ih] = [vidElem.videoWidth, vidElem.videoHeight]; + source = vidElem; + } else + return import_buffer2.Buffer.alloc(0); + const scale = Math.min(1, sw / iw, sh / ih); + const dims = [~~(iw * scale), ~~(ih * scale)]; + can.width = dims[0]; + can.height = dims[1]; + const ctx = can.getContext("2d"); + if (!ctx) + return import_buffer2.Buffer.alloc(0); + ctx.drawImage(source, 0, 0, dims[0], dims[1]); + const blob = await new Promise((_) => can.toBlob(_)); + if (!blob) + return import_buffer2.Buffer.alloc(0); + return import_buffer2.Buffer.from(await blob.arrayBuffer()); + }; var generateThumbnail = async (f) => { + try { + return await generateProperThumbnail(f); + } catch { + return await generateUglyThumbnail(f); + } + }; + var generateProperThumbnail = async (f) => { const can = document.createElement("canvas"); const [sw, sh] = [125, 125]; const url = URL.createObjectURL(f); @@ -15972,7 +16017,8 @@ t1 = text(ctx[0]); t2 = space(); h4 = element("h4"); - h4.innerHTML = `Join us on 2chen! \u2022 Install JKCS!`; + h4.innerHTML = `Join us on 2chen! \u2022 + Install JKCS!`; t6 = space(); hr = element("hr"); t7 = space(); @@ -18631,7 +18677,12 @@ const content = await navigator.clipboard.readText(); set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); } catch { - alert("How can you fail so badly? pathetic..."); + try { + const content = prompt("Paste it in here") || ""; + set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); + } catch { + alert("How can you fail so badly? pathetic..."); + } } }; const boardname = location.pathname.match(/\/([^/]*)\//)[1]; @@ -21847,6 +21898,15 @@ Use the WebExtension version of PEE if you want to use b4k!`); if (init4) return; init4 = true; + window.addEventListener("securitypolicyviolation", (e) => { + if (e.blockedURI.startsWith("blob")) { + if (supportedMainDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, add blob: to the allowed JS whitelist in 4chanX in Advanced Settings"); + } else if (supportedAltDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, use a CSP bypass extension like PEE-companion"); + } + } + }); const meta = document.querySelector('meta[name="referrer"]'); const customStyles = document.createElement("style"); customStyles.appendChild(document.createTextNode(global_default)); @@ -21956,9 +22016,9 @@ Use the WebExtension version of PEE if you want to use b4k!`); cp = new CommandProcessor(); } catch { if (false) - alert("The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); + fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); else - alert("You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); + fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); return; } if (!is4chanX && location.host.startsWith("boards.4chan")) { diff --git a/chrome/manifest.json b/chrome/manifest.json index 875398f..a0a8118 100644 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -2,7 +2,7 @@ "manifest_version": 3, "name": "PngExtraEmbedder", "description": "Discover embedded files on 4chan and archives!", - "version": "0.315", + "version": "0.320", "icons": { "64": "1449696017588.png" }, diff --git a/dist/main.js b/dist/main.js index 0c08b36..1246ce9 100644 --- a/dist/main.js +++ b/dist/main.js @@ -73,7 +73,7 @@ var define_BUILD_VERSION_default; var init_define_BUILD_VERSION = __esm({ ""() { - define_BUILD_VERSION_default = [0, 315]; + define_BUILD_VERSION_default = [0, 320]; } }); @@ -10751,7 +10751,52 @@ settings.subscribe((b) => { csettings = b; }); + var generateUglyThumbnail = async (f) => { + const can = document.createElement("canvas"); + const [sw, sh] = [125, 125]; + const url = URL.createObjectURL(f); + let source; + let iw, ih; + if (f.type.startsWith("image")) { + const imgElem = document.createElement("img"); + imgElem.src = url; + await new Promise((_) => imgElem.onload = _); + [iw, ih] = [imgElem.naturalWidth, imgElem.naturalHeight]; + source = imgElem; + } else if (f.type.startsWith("video")) { + const vidElem = document.createElement("video"); + vidElem.src = url; + await new Promise((_) => vidElem.onloadedmetadata = _); + vidElem.currentTime = 0; + await new Promise((_) => vidElem.onloadeddata = _); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + [iw, ih] = [vidElem.videoWidth, vidElem.videoHeight]; + source = vidElem; + } else + return import_buffer2.Buffer.alloc(0); + const scale = Math.min(1, sw / iw, sh / ih); + const dims = [~~(iw * scale), ~~(ih * scale)]; + can.width = dims[0]; + can.height = dims[1]; + const ctx = can.getContext("2d"); + if (!ctx) + return import_buffer2.Buffer.alloc(0); + ctx.drawImage(source, 0, 0, dims[0], dims[1]); + const blob = await new Promise((_) => can.toBlob(_)); + if (!blob) + return import_buffer2.Buffer.alloc(0); + return import_buffer2.Buffer.from(await blob.arrayBuffer()); + }; var generateThumbnail = async (f) => { + try { + return await generateProperThumbnail(f); + } catch { + return await generateUglyThumbnail(f); + } + }; + var generateProperThumbnail = async (f) => { const can = document.createElement("canvas"); const [sw, sh] = [125, 125]; const url = URL.createObjectURL(f); @@ -15784,7 +15829,8 @@ t1 = text(ctx[0]); t2 = space(); h4 = element("h4"); - h4.innerHTML = `Join us on 2chen! \u2022 Install JKCS!`; + h4.innerHTML = `Join us on 2chen! \u2022 + Install JKCS!`; t6 = space(); hr = element("hr"); t7 = space(); @@ -18443,7 +18489,12 @@ const content = await navigator.clipboard.readText(); set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); } catch { - alert("How can you fail so badly? pathetic..."); + try { + const content = prompt("Paste it in here") || ""; + set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); + } catch { + alert("How can you fail so badly? pathetic..."); + } } }; const boardname = location.pathname.match(/\/([^/]*)\//)[1]; @@ -21747,6 +21798,15 @@ Use the WebExtension version of PEE if you want to use b4k!`); if (init4) return; init4 = true; + window.addEventListener("securitypolicyviolation", (e) => { + if (e.blockedURI.startsWith("blob")) { + if (supportedMainDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, add blob: to the allowed JS whitelist in 4chanX in Advanced Settings"); + } else if (supportedAltDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, use a CSP bypass extension like PEE-companion"); + } + } + }); const meta = document.querySelector('meta[name="referrer"]'); const customStyles = document.createElement("style"); customStyles.appendChild(document.createTextNode(global_default)); @@ -21856,9 +21916,9 @@ Use the WebExtension version of PEE if you want to use b4k!`); cp = new CommandProcessor(); } catch { if (true) - alert("The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); + fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); else - alert("You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); + fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); return; } if (!is4chanX && location.host.startsWith("boards.4chan")) { diff --git a/firefox/dist/main.js b/firefox/dist/main.js index 9d4399f..a6898c3 100644 --- a/firefox/dist/main.js +++ b/firefox/dist/main.js @@ -73,7 +73,7 @@ var define_BUILD_VERSION_default; var init_define_BUILD_VERSION = __esm({ ""() { - define_BUILD_VERSION_default = [0, 315]; + define_BUILD_VERSION_default = [0, 320]; } }); @@ -10892,7 +10892,52 @@ settings.subscribe((b) => { csettings = b; }); + var generateUglyThumbnail = async (f) => { + const can = document.createElement("canvas"); + const [sw, sh] = [125, 125]; + const url = URL.createObjectURL(f); + let source; + let iw, ih; + if (f.type.startsWith("image")) { + const imgElem = document.createElement("img"); + imgElem.src = url; + await new Promise((_) => imgElem.onload = _); + [iw, ih] = [imgElem.naturalWidth, imgElem.naturalHeight]; + source = imgElem; + } else if (f.type.startsWith("video")) { + const vidElem = document.createElement("video"); + vidElem.src = url; + await new Promise((_) => vidElem.onloadedmetadata = _); + vidElem.currentTime = 0; + await new Promise((_) => vidElem.onloadeddata = _); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + [iw, ih] = [vidElem.videoWidth, vidElem.videoHeight]; + source = vidElem; + } else + return import_buffer2.Buffer.alloc(0); + const scale = Math.min(1, sw / iw, sh / ih); + const dims = [~~(iw * scale), ~~(ih * scale)]; + can.width = dims[0]; + can.height = dims[1]; + const ctx = can.getContext("2d"); + if (!ctx) + return import_buffer2.Buffer.alloc(0); + ctx.drawImage(source, 0, 0, dims[0], dims[1]); + const blob = await new Promise((_) => can.toBlob(_)); + if (!blob) + return import_buffer2.Buffer.alloc(0); + return import_buffer2.Buffer.from(await blob.arrayBuffer()); + }; var generateThumbnail = async (f) => { + try { + return await generateProperThumbnail(f); + } catch { + return await generateUglyThumbnail(f); + } + }; + var generateProperThumbnail = async (f) => { const can = document.createElement("canvas"); const [sw, sh] = [125, 125]; const url = URL.createObjectURL(f); @@ -15949,7 +15994,8 @@ t1 = text(ctx[0]); t2 = space(); h4 = element("h4"); - h4.innerHTML = `Join us on 2chen! \u2022 Install JKCS!`; + h4.innerHTML = `Join us on 2chen! \u2022 + Install JKCS!`; t6 = space(); hr = element("hr"); t7 = space(); @@ -18608,7 +18654,12 @@ const content = await navigator.clipboard.readText(); set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); } catch { - alert("How can you fail so badly? pathetic..."); + try { + const content = prompt("Paste it in here") || ""; + set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); + } catch { + alert("How can you fail so badly? pathetic..."); + } } }; const boardname = location.pathname.match(/\/([^/]*)\//)[1]; @@ -21824,6 +21875,15 @@ Use the WebExtension version of PEE if you want to use b4k!`); if (init4) return; init4 = true; + window.addEventListener("securitypolicyviolation", (e) => { + if (e.blockedURI.startsWith("blob")) { + if (supportedMainDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, add blob: to the allowed JS whitelist in 4chanX in Advanced Settings"); + } else if (supportedAltDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, use a CSP bypass extension like PEE-companion"); + } + } + }); const meta = document.querySelector('meta[name="referrer"]'); const customStyles = document.createElement("style"); customStyles.appendChild(document.createTextNode(global_default)); @@ -21933,9 +21993,9 @@ Use the WebExtension version of PEE if you want to use b4k!`); cp = new CommandProcessor(); } catch { if (false) - alert("The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); + fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); else - alert("You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); + fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); return; } if (!is4chanX && location.host.startsWith("boards.4chan")) { diff --git a/firefox/manifest.json b/firefox/manifest.json index e24dc0f..bcc5015 100644 --- a/firefox/manifest.json +++ b/firefox/manifest.json @@ -7,7 +7,7 @@ }, "name": "PngExtraEmbedder", "description": "Discover embedded files on 4chan and archives!", - "version": "0.315", + "version": "0.320", "icons": { "64": "1449696017588.png" }, diff --git a/firefox_update.json b/firefox_update.json index 3314cea..dfeec41 100644 --- a/firefox_update.json +++ b/firefox_update.json @@ -1 +1 @@ -{"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.315","update_link":"https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.315.xpi"}]}}} \ No newline at end of file +{"addons":{"{34ac4994-07f2-44d2-8599-682516a6c6a6}":{"updates":[{"version":"0.320","update_link":"https://git.coom.tech/fuckjannies/lolipiss/raw/branch/%E4%B8%AD%E5%87%BA%E3%81%97/pngextraembedder-0.320.xpi"}]}}} \ No newline at end of file diff --git a/main.meta.js b/main.meta.js index 19a6d69..4bc3869 100644 --- a/main.meta.js +++ b/main.meta.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.315 +// @version 0.320 // @description uhh // @author You // @match https://boards.4channel.org/* diff --git a/main.user.js b/main.user.js index 988c3b9..74fcddb 100644 --- a/main.user.js +++ b/main.user.js @@ -1,7 +1,7 @@ // ==UserScript== // @name PNGExtraEmbed // @namespace https://coom.tech/ -// @version 0.315 +// @version 0.320 // @description uhh // @author You // @match https://boards.4channel.org/* @@ -109,7 +109,7 @@ const _DOMParser = DOMParser; var define_BUILD_VERSION_default; var init_define_BUILD_VERSION = __esm({ ""() { - define_BUILD_VERSION_default = [0, 315]; + define_BUILD_VERSION_default = [0, 320]; } }); @@ -10787,7 +10787,52 @@ const _DOMParser = DOMParser; settings.subscribe((b) => { csettings = b; }); + var generateUglyThumbnail = async (f) => { + const can = document.createElement("canvas"); + const [sw, sh] = [125, 125]; + const url = URL.createObjectURL(f); + let source; + let iw, ih; + if (f.type.startsWith("image")) { + const imgElem = document.createElement("img"); + imgElem.src = url; + await new Promise((_) => imgElem.onload = _); + [iw, ih] = [imgElem.naturalWidth, imgElem.naturalHeight]; + source = imgElem; + } else if (f.type.startsWith("video")) { + const vidElem = document.createElement("video"); + vidElem.src = url; + await new Promise((_) => vidElem.onloadedmetadata = _); + vidElem.currentTime = 0; + await new Promise((_) => vidElem.onloadeddata = _); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + await new Promise(requestAnimationFrame); + [iw, ih] = [vidElem.videoWidth, vidElem.videoHeight]; + source = vidElem; + } else + return import_buffer2.Buffer.alloc(0); + const scale = Math.min(1, sw / iw, sh / ih); + const dims = [~~(iw * scale), ~~(ih * scale)]; + can.width = dims[0]; + can.height = dims[1]; + const ctx = can.getContext("2d"); + if (!ctx) + return import_buffer2.Buffer.alloc(0); + ctx.drawImage(source, 0, 0, dims[0], dims[1]); + const blob = await new Promise((_) => can.toBlob(_)); + if (!blob) + return import_buffer2.Buffer.alloc(0); + return import_buffer2.Buffer.from(await blob.arrayBuffer()); + }; var generateThumbnail = async (f) => { + try { + return await generateProperThumbnail(f); + } catch { + return await generateUglyThumbnail(f); + } + }; + var generateProperThumbnail = async (f) => { const can = document.createElement("canvas"); const [sw, sh] = [125, 125]; const url = URL.createObjectURL(f); @@ -15820,7 +15865,8 @@ const _DOMParser = DOMParser; t1 = text(ctx[0]); t2 = space(); h4 = element("h4"); - h4.innerHTML = `Join us on 2chen! \u2022 Install JKCS!`; + h4.innerHTML = `Join us on 2chen! \u2022 + Install JKCS!`; t6 = space(); hr = element("hr"); t7 = space(); @@ -18479,7 +18525,12 @@ const _DOMParser = DOMParser; const content = await navigator.clipboard.readText(); set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); } catch { - alert("How can you fail so badly? pathetic..."); + try { + const content = prompt("Paste it in here") || ""; + set_store_value(settings, $settings.rsources = JSON.parse(content), $settings); + } catch { + alert("How can you fail so badly? pathetic..."); + } } }; const boardname = location.pathname.match(/\/([^/]*)\//)[1]; @@ -21783,6 +21834,15 @@ Use the WebExtension version of PEE if you want to use b4k!`); if (init4) return; init4 = true; + window.addEventListener("securitypolicyviolation", (e) => { + if (e.blockedURI.startsWith("blob")) { + if (supportedMainDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, add blob: to the allowed JS whitelist in 4chanX in Advanced Settings"); + } else if (supportedAltDomain(location.host)) { + fireNotification("error", "CSP is preventing PEE from running, use a CSP bypass extension like PEE-companion"); + } + } + }); const meta = document.querySelector('meta[name="referrer"]'); const customStyles = document.createElement("style"); customStyles.appendChild(document.createTextNode(global_default)); @@ -21892,9 +21952,9 @@ Use the WebExtension version of PEE if you want to use b4k!`); cp = new CommandProcessor(); } catch { if (true) - alert("The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); + fireNotification("error", "The page you're on has a CSP that prevents PEE from functionning properly.\n\n If using 4chanX, Add 'blob:' to the JS whitelist. Else, install PEE-companion."); else - alert("You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); + fireNotification("error", "You may be using 4chanX\n\nGo to 4chanX's settings, Advanced > JS Whitelist and add 'blob:' without quotes to the list."); return; } if (!is4chanX && location.host.startsWith("boards.4chan")) { diff --git a/pngextraembedder-0.320.xpi b/pngextraembedder-0.320.xpi new file mode 100644 index 0000000..baca0e3 Binary files /dev/null and b/pngextraembedder-0.320.xpi differ