Last active
March 21, 2024 01:11
-
-
Save kirisakow/198dc7b9545f61fced36735203eb5e44 to your computer and use it in GitHub Desktop.
Automatically unfold collapsed sections on webpages.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==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