Browse Source

Temporary Perfomance fix: Delegate processing of posts to until 3200px away from ViewPort

Anonymous 2 years ago
parent
commit
cae39c3c5f
  1. 2
      main.meta.js
  2. 38
      main.user.js
  3. 34
      src/main.ts

2
main.meta.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.113
// @version 0.115
// @description uhh
// @author You
// @match https://boards.4channel.org/*

38
main.user.js

@ -1,7 +1,7 @@
// ==UserScript==
// @name PNGExtraEmbed
// @namespace https://coom.tech/
// @version 0.113
// @version 0.115
// @description uhh
// @author You
// @match https://boards.4channel.org/*
@ -15899,7 +15899,7 @@
// src/EyeButton.svelte
init_esbuild_inject();
function add_css7(target) {
append_styles(target, "svelte-jnv079", ".clickable.svelte-jnv079{cursor:pointer;margin-left:2px;margin-right:2px;text-decoration:underline}.clickable.svelte-jnv079:hover{text-shadow:0 0 4px palevioletred}");
append_styles(target, "svelte-1bbaka0", ".clickable.svelte-1bbaka0{cursor:pointer;margin-left:2px;margin-right:2px}.clickable.svelte-1bbaka0:hover{text-shadow:0 0 4px palevioletred}");
}
function get_each_context4(ctx, list, i) {
const child_ctx = ctx.slice();
@ -15913,7 +15913,7 @@
return {
c() {
span = element("span");
attr(span, "class", "fa clickable svelte-jnv079");
attr(span, "class", "fa clickable svelte-1bbaka0");
toggle_class(span, "fa-eye", !ctx[3]);
toggle_class(span, "fa-eye-slash", ctx[3]);
},
@ -15950,7 +15950,7 @@
t = text("Source");
attr(a, "href", a_href_value = ctx[11].source);
attr(a, "target", "_blank");
attr(a, "class", "clickable svelte-jnv079");
attr(a, "class", "clickable svelte-1bbaka0");
},
m(target, anchor) {
insert(target, a, anchor);
@ -15978,7 +15978,7 @@
t = text(t_value);
attr(a, "href", a_href_value = ctx[11].page.url);
attr(a, "target", "_blank");
attr(a, "class", "clickable svelte-jnv079");
attr(a, "class", "clickable svelte-1bbaka0");
},
m(target, anchor) {
insert(target, a, anchor);
@ -16006,7 +16006,7 @@
a = element("a");
a.textContent = "[PEE contract]";
attr(a, "alt", "By clicking this you agree to stay hydrated");
attr(a, "class", "clickable svelte-jnv079");
attr(a, "class", "clickable svelte-1bbaka0");
},
m(target, anchor) {
insert(target, a, anchor);
@ -16053,7 +16053,7 @@
if_block2.c();
if_block2_anchor = empty();
attr(span, "title", span_title_value = ctx[11].filename);
attr(span, "class", "fa fa-download clickable svelte-jnv079");
attr(span, "class", "fa fa-download clickable svelte-1bbaka0");
},
m(target, anchor) {
insert(target, span, anchor);
@ -16412,14 +16412,22 @@
...cappState,
isCatalog: !!document.querySelector(".catalog-small") || !!location.pathname.match(/\/catalog$/)
});
const n = 7;
const range = ~~(posts.length / n) + 1;
await Promise.all([...new Array(n + 1)].map(async (e, i) => {
const postsslice = posts.slice(i * range, (i + 1) * range);
for (const post of postsslice) {
await processPost(post);
}
}));
const obs = new IntersectionObserver((entries, obs2) => {
setTimeout(() => {
for (const item of entries) {
if (!item.isIntersecting)
continue;
const target = item.target;
if (target instanceof HTMLDivElement) {
processPost(target);
} else {
debugger;
}
obs2.unobserve(target);
}
}, 1);
}, { root: null, rootMargin: "3200px", threshold: 0.01 });
posts.map((e) => obs.observe(e));
};
var getSelectedFile = () => {
return new Promise((res) => {

34
src/main.ts

@ -184,17 +184,35 @@ const startup = async () => {
...cappState,
isCatalog: !!document.querySelector('.catalog-small') || !!location.pathname.match(/\/catalog$/),
});
/* Temporary change for better performance */
const obs = new IntersectionObserver((entries, obs) => {
setTimeout(()=>{
for(const item of entries) {
if(!item.isIntersecting) continue;
const target = item.target;
if(target instanceof HTMLDivElement){
processPost(target);
}else{
debugger;
}
obs.unobserve(target);
}
}, 1);
}, {root:null, rootMargin: '3200px', threshold: 0.01});
posts.map(e => obs.observe(e as any));
// for (let i = 159; i < 160 ;++i)
// await processPost(posts[i] as any);
const n = 7;
const range = ~~(posts.length / n) + 1;
await Promise.all([...new Array(n + 1)].map(async (e, i) => {
const postsslice = posts.slice(i * range, (i + 1) * range);
for (const post of postsslice) {
await processPost(post as any);
}
}));
// const n = 7;
// const range = ~~(posts.length / n) + 1;
// await Promise.all([...new Array(n + 1)].map(async (e, i) => {
// const postsslice = posts.slice(i * range, (i + 1) * range);
// for (const post of postsslice) {
// await processPost(post as any);
// }
// }));
//await Promise.all(posts.map(e => processPost(e as any)));
};

Loading…
Cancel
Save