Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
freelancer.com country filter
// ==UserScript==
// @name freelancer.com country filter
// @namespace https://drawcode.eu/
// @include https://www.freelancer.com/projects/*
// @version 1
// @grant none
// ==/UserScript==
// Commented script needs to run in web console on a job search page (e.g. in a separate Firefox profile to avoid new tab focus and tabs overflow)
// You need to be logged in because the logged out page is different and displays less jobs
/*
var links = document.getElementsByClassName("JobSearchCard-primary-heading");
var length = links.length;
var i = -1;
(function searchJobs() {
++i;
if (i < length) {
if (links[i].children.length > 2) { // can decrease spam by only opening job offers with verified payment method (remove the if condition and else block if you want to see these jobs)
window.open(links[i].firstElementChild.href);
setTimeout(function(){searchJobs();}, 5000); // open new URL every 5 seconds (could be changed without breaking the script)
}
else {
searchJobs();
}
}
})();
*/
// Script to use with a browser addon like Greasemonkey, to run after page load when opening a new job
// Page load is slow because the website DOM is created on the client-side with JavaScript and AJAX
// The script could be faster by using the website API directly but it could be flagged as a bot
// add or remove country codes as needed (GB is used instead of UK)
var countries = ["gb","ie","fr","de","ch","es","pt","it","be","lu","nl","dk","at","se","fi","no","is"];
var found = false;
var targetNode = document.getElementsByTagName("app-root")[0];
var config = {childList: true, subtree: true};
var callback = function(mutationsList, observer) {
for (var i = 0; found != true; ++i) {
if (mutationsList[i].addedNodes[0].nodeName == "FL-CARD") {
// only search country flag if we got a correct node name
var flag = document.getElementsByClassName("FlagImage")[0];
if (flag) {
found = true;
observer.disconnect();
if (!countries.includes(flag.title)) {
window.close();
}
}
}
}
};
var observer = new MutationObserver(callback);
observer.observe(targetNode, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment