Browse Source

Fix #9, adjust CSS to be more compact/more consistent

pull/46/head latest
coomdev 2 years ago
parent
commit
d52e5863be
  1. 1
      build.js
  2. 3
      main.meta.js
  3. 40
      main.user.js
  4. 2
      src/Embedding.svelte
  5. 4
      src/global.css
  6. 34
      src/main.ts

1
build.js

@ -25,6 +25,7 @@ const extheader = `// ==UserScript==
// @connect 4chan.org // @connect 4chan.org
// @connect 4channel.org // @connect 4channel.org
// @connect i.4cdn.org // @connect i.4cdn.org
// @icon https://coom.tech/resources/assets/1449696017588.png
// ==/UserScript== // ==/UserScript==
`; `;

3
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.82 // @version 0.84
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @match https://boards.4channel.org/*
@ -14,4 +14,5 @@
// @connect 4chan.org // @connect 4chan.org
// @connect 4channel.org // @connect 4channel.org
// @connect i.4cdn.org // @connect i.4cdn.org
// @icon https://coom.tech/resources/assets/1449696017588.png
// ==/UserScript== // ==/UserScript==

40
main.user.js

@ -1,7 +1,7 @@
// ==UserScript== // ==UserScript==
// @name PNGExtraEmbed // @name PNGExtraEmbed
// @namespace https://coom.tech/ // @namespace https://coom.tech/
// @version 0.82 // @version 0.84
// @description uhh // @description uhh
// @author You // @author You
// @match https://boards.4channel.org/* // @match https://boards.4channel.org/*
@ -14,6 +14,7 @@
// @connect 4chan.org // @connect 4chan.org
// @connect 4channel.org // @connect 4channel.org
// @connect i.4cdn.org // @connect i.4cdn.org
// @icon https://coom.tech/resources/assets/1449696017588.png
// ==/UserScript== // ==/UserScript==
(() => { (() => {
var __create = Object.create; var __create = Object.create;
@ -10896,7 +10897,7 @@
}); });
// src/global.css // src/global.css
var global_default = ".pee-hidden {\n display: none;\n}\n\n.extractedImg {\n width: auto;\n height: auto;\n max-width: 125px;\n max-height: 125px;\n cursor: pointer;\n}\n\n#delform .postContainer>div.hasembed {\n border-right: 3px dashed deeppink !important;\n}\n\n.hasembed.catalog-post {\n border: 3px dashed deeppink !important;\n}\n\n#delform .postContainer>div.hasext {\n border-right: 3px dashed goldenrod !important;\n}\n\n.hasext.catalog-post {\n border: 3px dashed goldenrod !important;\n}\n\n.expanded-image>.post>.file .fileThumb>img[data-md5] {\n display: none;\n}\n\n.expanded-image>.post>.file .fileThumb .full-image {\n display: inline;\n}\n\n.pee-settings {\n position: fixed;\n top: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n}\n\ndiv.hasemb .catalog-host img {\n border: 1px solid deeppink;\n}\n\ndiv.hasext .catalog-host img {\n border: 1px solid goldenrod;\n}\n\n.catalog-host img {\n position: absolute;\n top: -5px;\n right: 0px;\n max-width: 80px;\n max-height: 80px;\n box-shadow: 0px 0px 4px 2px #00000090;\n}"; var global_default = ".pee-hidden {\n display: none;\n}\n\n.extractedImg {\n width: auto;\n height: auto;\n max-width: 125px;\n max-height: 125px;\n cursor: pointer;\n}\n\n#delform .postContainer>div.hasembed {\n border-right: 3px dashed deeppink !important;\n}\n\n.hasembed.catalog-post {\n border: 3px dashed deeppink !important;\n}\n\n#delform .postContainer>div.hasext {\n border-right: 3px dashed goldenrod !important;\n}\n\n.hasext.catalog-post {\n border: 3px dashed goldenrod !important;\n}\n\n.expanded-image>.post>.file .fileThumb>img[data-md5] {\n display: none;\n}\n\n.expanded-image>.post>.file .fileThumb .full-image {\n display: inline;\n}\n\n.pee-settings {\n position: fixed;\n top: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n}\n\ndiv.hasemb .catalog-host img {\n border: 1px solid deeppink;\n}\n\ndiv.hasext .catalog-host img {\n border: 1px solid goldenrod;\n}\n\n.catalog-host img {\n position: absolute;\n top: -5px;\n right: 0px;\n max-width: 80px;\n max-height: 80px;\n box-shadow: 0px 0px 4px 2px #00000090;\n}\n\n.fileThumb.filehost {\n margin-left: 0 !important;\n}";
// src/png.ts // src/png.ts
init_esbuild_inject(); init_esbuild_inject();
@ -13900,7 +13901,7 @@
t4 = space(); t4 = space();
if (if_block5) if (if_block5)
if_block5.c(); if_block5.c();
attr(div0, "class", "place fileThumb svelte-vw6znf"); attr(div0, "class", "place svelte-vw6znf");
toggle_class(div0, "contract", ctx[5]); toggle_class(div0, "contract", ctx[5]);
attr(div1, "class", "hoverer svelte-vw6znf"); attr(div1, "class", "hoverer svelte-vw6znf");
toggle_class(div1, "visible", ctx[6] && ctx[5]); toggle_class(div1, "visible", ctx[6] && ctx[5]);
@ -14747,8 +14748,8 @@
}; };
var textToElement = (s) => document.createRange().createContextualFragment(s).children[0]; var textToElement = (s) => document.createRange().createContextualFragment(s).children[0];
var processPost = async (post) => { var processPost = async (post) => {
const thumb = post.querySelector(".fileThumb"); const thumb = post.querySelector("a.fileThumb");
const origlink = post.querySelector(".file-info > a"); const origlink = post.querySelector('.file-info > a[target*="_blank"]');
if (!thumb || !origlink) if (!thumb || !origlink)
return; return;
const res2 = await processImage(origlink.href, (origlink.querySelector(".fnfull") || origlink).textContent || ""); const res2 = await processImage(origlink.href, (origlink.querySelector(".fnfull") || origlink).textContent || "");
@ -14762,18 +14763,23 @@
replyBox?.classList.add("hasembed"); replyBox?.classList.add("hasembed");
const isCatalog = replyBox?.classList.contains("catalog-post"); const isCatalog = replyBox?.classList.contains("catalog-post");
if (!isCatalog) { if (!isCatalog) {
const ft = thumb; const ft = post.querySelector("div.file");
const ahem = ft.querySelector(".place"); const info = post.querySelector("span.file-info");
const imgcont = ahem || document.createElement("div"); const filehost = ft.querySelector(".filehost");
const eyecont = ahem || document.createElement("span"); const eyehost = info.querySelector(".eyehost");
const p = thumb.parentElement; const imgcont = filehost || document.createElement("div");
if (!ahem) { const eyecont = eyehost || document.createElement("span");
p.removeChild(thumb); if (!filehost) {
imgcont.appendChild(thumb); ft.append(imgcont);
imgcont.classList.add("fileThumb"); imgcont.classList.add("fileThumb");
replyBox?.querySelector("a[download]").insertAdjacentElement("afterend", eyecont); imgcont.classList.add("filehost");
} else { } else {
imgcont.innerHTML = ""; imgcont.innerHTML = "";
}
if (!eyehost) {
info.append(eyecont);
eyecont.classList.add("eyehost");
} else {
eyecont.innerHTML = ""; eyecont.innerHTML = "";
} }
const id = ~~(Math.random() * 2e7); const id = ~~(Math.random() * 2e7);
@ -14791,8 +14797,6 @@
id: "" + id id: "" + id
} }
}); });
if (!ahem)
p.appendChild(imgcont);
} else { } else {
const opFile = post.querySelector(".catalog-link"); const opFile = post.querySelector(".catalog-link");
const ahem = opFile?.querySelector(".catalog-host"); const ahem = opFile?.querySelector(".catalog-host");
@ -14827,7 +14831,7 @@
rec.addedNodes.forEach((e) => { rec.addedNodes.forEach((e) => {
if (!(e instanceof HTMLElement)) if (!(e instanceof HTMLElement))
return; return;
let el = e.querySelectorAll(".postContainer"); let el = e.querySelectorAll('.postContainer:not([class*="noFile"])');
if (!el && e.classList.contains("postContainer")) if (!el && e.classList.contains("postContainer"))
el = e; el = e;
if (el) if (el)
@ -14837,7 +14841,7 @@
document.querySelectorAll(".board").forEach((e) => { document.querySelectorAll(".board").forEach((e) => {
mo.observe(e, { childList: true, subtree: true }); mo.observe(e, { childList: true, subtree: true });
}); });
const posts = [...document.querySelectorAll(".postContainer")]; const posts = [...document.querySelectorAll('.postContainer:not([class*="noFile"])')];
const scts = document.getElementById("shortcuts"); const scts = document.getElementById("shortcuts");
const button = textToElement(`<span></span>`); const button = textToElement(`<span></span>`);
const settingsButton = new SettingsButton_default({ const settingsButton = new SettingsButton_default({

2
src/Embedding.svelte

@ -195,7 +195,7 @@
<!-- svelte-ignore a11y-mouse-events-have-key-events --> <!-- svelte-ignore a11y-mouse-events-have-key-events -->
<div <div
class:contract={contracted} class:contract={contracted}
class="place fileThumb" class="place"
on:click={() => bepis()} on:click={() => bepis()}
on:mouseover={hoverStart} on:mouseover={hoverStart}
on:mouseout={hoverStop} on:mouseout={hoverStop}

4
src/global.css

@ -57,4 +57,8 @@ div.hasext .catalog-host img {
max-width: 80px; max-width: 80px;
max-height: 80px; max-height: 80px;
box-shadow: 0px 0px 4px 2px #00000090; box-shadow: 0px 0px 4px 2px #00000090;
}
.fileThumb.filehost {
margin-left: 0 !important;
} }

34
src/main.ts

@ -112,8 +112,8 @@ const textToElement = <T = HTMLElement>(s: string) =>
document.createRange().createContextualFragment(s).children[0] as any as T; document.createRange().createContextualFragment(s).children[0] as any as T;
const processPost = async (post: HTMLDivElement) => { const processPost = async (post: HTMLDivElement) => {
const thumb = post.querySelector(".fileThumb") as HTMLAnchorElement; const thumb = post.querySelector("a.fileThumb") as HTMLAnchorElement;
const origlink = post.querySelector('.file-info > a') as HTMLAnchorElement; const origlink = post.querySelector('.file-info > a[target*="_blank"]') as HTMLAnchorElement;
if (!thumb || !origlink) if (!thumb || !origlink)
return; return;
const res2 = await processImage(origlink.href, (origlink.querySelector('.fnfull') || origlink).textContent || ''); const res2 = await processImage(origlink.href, (origlink.querySelector('.fnfull') || origlink).textContent || '');
@ -127,19 +127,25 @@ const processPost = async (post: HTMLDivElement) => {
const isCatalog = replyBox?.classList.contains('catalog-post'); const isCatalog = replyBox?.classList.contains('catalog-post');
// add buttons // add buttons
if (!isCatalog) { if (!isCatalog) {
const ft = thumb; const ft = post.querySelector('div.file') as HTMLDivElement;
const ahem: HTMLElement | null = ft.querySelector('.place'); const info = post.querySelector("span.file-info") as HTMLSpanElement;
const imgcont = ahem || document.createElement('div');
const eyecont = ahem || document.createElement('span'); const filehost: HTMLElement | null = ft.querySelector('.filehost');
const p = thumb.parentElement!; const eyehost: HTMLElement | null = info.querySelector('.eyehost');
const imgcont = filehost || document.createElement('div');
const eyecont = eyehost || document.createElement('span');
if (!ahem) { if (!filehost) {
p.removeChild(thumb); ft.append(imgcont);
imgcont.appendChild(thumb);
imgcont.classList.add("fileThumb"); imgcont.classList.add("fileThumb");
replyBox?.querySelector('a[download]')!.insertAdjacentElement("afterend", eyecont); imgcont.classList.add("filehost");
} else { } else {
imgcont.innerHTML = ''; imgcont.innerHTML = '';
}
if (!eyehost) {
info.append(eyecont);
eyecont.classList.add("eyehost");
} else {
eyecont.innerHTML = ''; eyecont.innerHTML = '';
} }
const id = ~~(Math.random() * 20000000); const id = ~~(Math.random() * 20000000);
@ -157,8 +163,6 @@ const processPost = async (post: HTMLDivElement) => {
id: '' + id id: '' + id
} }
}); });
if (!ahem)
p.appendChild(imgcont);
} else { } else {
const opFile = post.querySelector('.catalog-link'); const opFile = post.querySelector('.catalog-link');
const ahem = opFile?.querySelector('.catalog-host'); const ahem = opFile?.querySelector('.catalog-host');
@ -201,7 +205,7 @@ const startup = async () => {
if (!(e instanceof HTMLElement)) if (!(e instanceof HTMLElement))
return; return;
// apparently querySelector cannot select the root element if it matches // apparently querySelector cannot select the root element if it matches
let el = (e as any).querySelectorAll(".postContainer"); let el = (e as any).querySelectorAll('.postContainer:not([class*="noFile"])');
if (!el && e.classList.contains('postContainer')) if (!el && e.classList.contains('postContainer'))
el = e; el = e;
if (el) if (el)
@ -212,7 +216,7 @@ const startup = async () => {
document.querySelectorAll('.board').forEach(e => { document.querySelectorAll('.board').forEach(e => {
mo.observe(e!, { childList: true, subtree: true }); mo.observe(e!, { childList: true, subtree: true });
}); });
const posts = [...document.querySelectorAll('.postContainer')]; const posts = [...document.querySelectorAll('.postContainer:not([class*="noFile"])')];
const scts = document.getElementById('shortcuts'); const scts = document.getElementById('shortcuts');
const button = textToElement(`<span></span>`); const button = textToElement(`<span></span>`);

Loading…
Cancel
Save