Skip to content

Instantly share code, notes, and snippets.

@kirisakow
Last active March 21, 2024 01:11
Show Gist options
  • Save kirisakow/198dc7b9545f61fced36735203eb5e44 to your computer and use it in GitHub Desktop.
Save kirisakow/198dc7b9545f61fced36735203eb5e44 to your computer and use it in GitHub Desktop.
Automatically unfold collapsed sections on webpages.
// ==UserScript==
// @name unfoldCollapsed.user.js
// @description Automatically unfold collapsed sections on webpages.
// @version 1
// @grant unsafeWindow
// @include https://www.apec.fr/*
// @include https://nofluffjobs.com/*
// @include https://choisirleservicepublic.gouv.fr/*
// @include https://www.welcometothejungle.com/*
// ==/UserScript==
var myInterval;
const intervalInMs = 500;
const cssSelectorByDomain = {
"apec.fr": "p.m-0 label span",
"nofluffjobs.com": "a[class~=read-more]",
"choisirleservicepublic.gouv.fr": "button.text-clamp--cta",
"welcometothejungle.com": "div.wui-text > a"
};
function unfoldCollapsedSections() {
for (const [domainName, cssSelector] of Object.entries(cssSelectorByDomain)) {
if (!location.host.includes(domainName)) {
continue;
}
var buttonsToClickToUnfold = document.querySelectorAll(cssSelector);
if (!buttonsToClickToUnfold || buttonsToClickToUnfold.length == 0) {
return;
}
buttonsToClickToUnfold.forEach((element) => {
try {
element.click();
} catch (e) {
element.dispatchEvent(new Event("click"));
}
});
clearInterval(myInterval);
}
}
myInterval = setInterval(unfoldCollapsedSections, intervalInMs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment