返回首頁 

讨论»创建请求

Script doesn't work anymore, who can fix it?

发表于:2015-10-30
编辑于:2015-10-30

Script doesn't work anymore, who can fix it?

In 2012 mr Jefferson has created a (greasemonkey) script below for the website marktplaats.nl.It seems that marktplaats changed something because I can't get the script working any more.With firebug and common sence I can't see what is wrong but I guess it is something small.So I wanted to upload the script but the website userscripts is closedhttp://userscripts-mirror.org/topics/119213.html

Is it possible to have a look at it?

// ==UserScript==// @name        Change marktplaats prijstype// @namespace   bezoeker// @include     https://marktplaats.nl/syi/// @version     1// @grant       none// ==/UserScript==var prijs_links = document.querySelectorAll("#syi-price-tabs a");for (var cpt_count=0; cpt_count<prijs_links.length; cpt_count++){if (prijs_links[cpt_count].textContent == "Kies ander prijstype"){// Click the "Kies ander prijstype" linkprijs_links[cpt_count].click();// Click "Bieden" in the hidden unordered listvar prijs_listitems = document.querySelectorAll("#syi-price-type ul li");for (cpt_count=0; cpt_count<prijs_listitems.length; cpt_count++){if (prijs_listitems[cpt_count].textContent == "Bieden"){prijs_listitems[cpt_count].click();break;}}break;}}

To test the script use https://www.marktplaats.nl/syi/plaatsAdvertentie.html

Type word: boeken click :vind rubriek, click on the created link belowHalf way down in the new page the pricetype prijs appearsI need default Kies ander prijstype > bieden

Jefferson Scher wrote on my e-mail:

I added a console.log to the script and it seems that "clicking" the link using a script reloads/navigates the page while clicking interactively does not.And on the second load, the script fails.

prijs_links.length=2 in https://www.marktplaats.nl/syi/201/224/plaatsAdvertentie.html?bucket=37&origin=HEADER

prijs_links.length=0 in https://www.marktplaats.nl/syi/201/224/plaatsAdvertentie.html?bucket=37&origin=HEADER#syi-price-type

But when I try to fix this, it breaks the part of the form just below that...

// ==UserScript==// @name        Change prijstype// @namespace   YourNameHere// @include     https://www.marktplaats.nl/syi/*// @version     1// @grant       none// ==/UserScript==var prijs_links = document.querySelectorAll("a.syi-price-tab");console.log("**** Found: prijs_links.length="+prijs_links.length+" in "+location.href);for (var cpt_count=0; cpt_count<prijs_links.length; cpt_count++){if (prijs_links[cpt_count].textContent == "Kies ander prijstype"){// Click the "Kies ander prijstype" linkprijs_links[cpt_count].click();/* Try to prevent navigation by swapping out the href attribute temporarily: WRECKS FORMvar oldHref = prijs_links[cpt_count].href;prijs_links[cpt_count].href = "javascript:return false;";prijs_links[cpt_count].click();prijs_links[cpt_count].href = oldHref;*/// Click "Bieden" in the hidden unordered listvar prijs_listitems = document.querySelectorAll("#syi-price-type ul li");for (cpt_count=0; cpt_count<prijs_listitems.length; cpt_count++){if (prijs_listitems[cpt_count].textContent == "Bieden"){prijs_listitems[cpt_count].click();break;}}break;}}
发表于:2015-10-30

Oh hey, that's me.

Could you try this way. Instead of relying on the click events, it tries to make all the changes directly. I didn't submit the form, so I don't know whether I got everything.

function switchDisplay(){var ptabs = document.querySelectorAll('#syi-price-tabs a');if (ptabs.length == 0){window.setTimeout(switchDisplay, 500);return;}if (ptabs[1].className.indexOf("selected") > -1) return;// Switch selected classptabs[0].className = ptabs[0].className.replace("selected", "");ptabs[1].className += " selected";// Set hidden inputvar frm = document.getElementById("syi-form");frm.elements["price.option"].value = "priceType";// Change visibility of controlsdocument.getElementById("syi-price").style.display = "none";document.getElementById("syi-price-type").style.display = "block";// Set selected for "Bieden" option in the select controlvar ptv = frm.elements["price.typeValue"];for (var i=0; i<ptv.options.length; i++){if (ptv.options[i].textContent == "Bieden"){console.log("Found Bieden");ptv.options[i].selected = true;break;}}}if (window.self == window.top) window.setTimeout(switchDisplay, 1000);
发表于:2015-10-31

It works perfect, also with submit, Manny thanks Jefferson!

发表于:2015-10-31
编辑于:2015-10-31

Is it also possible to set "toon op kaart" not filled by default?

发表于:2015-11-01
Is it also possible to set "toon op kaart" not filled by default?

Took me a while to find that, since I'm not logged in, it's hidden.

function switchDisplay(){var ptabs = document.querySelectorAll('#syi-price-tabs a');if (ptabs.length == 0){window.setTimeout(switchDisplay, 500);return;}if (ptabs[1].className.indexOf("selected") > -1) return;// Switch selected classptabs[0].className = ptabs[0].className.replace("selected", "");ptabs[1].className += " selected";// Set hidden inputvar frm = document.getElementById("syi-form");frm.elements["price.option"].value = "priceType";// Change visibility of controlsdocument.getElementById("syi-price").style.display = "none";document.getElementById("syi-price-type").style.display = "block";// Set selected for "Bieden" option in the select controlvar ptv = frm.elements["price.typeValue"];for (var i=0; i<ptv.options.length; i++){if (ptv.options[i].textContent == "Bieden"){console.log("Found Bieden");ptv.options[i].selected = true;break;}}// Do not show location on mapvar chkMap = document.getElementById("show-on-map");if (chkMap){chkMap.checked = false;if (chkMap.hasAttribute("checked")) chkMap.removeAttribute("checked");}}if (window.self == window.top) window.setTimeout(switchDisplay, 1000);
发表于:2015-11-01

The show on map is ok but now I see that after the submit the price value choice is set to "gratis" instead of "bieden" it needs more work I am afraid

发表于:2015-11-01
编辑于:2015-11-01

What?? Try switching the order because I'm not seeing that:

function switchDisplay(){// Select pricingvar ptabs = document.querySelectorAll('#syi-price-tabs a');if (ptabs.length == 0){window.setTimeout(switchDisplay, 500);return;}if (ptabs[1].className.indexOf("selected") > -1) return;// Do not show location on mapvar chkMap = document.getElementById("show-on-map");if (chkMap){chkMap.checked = false;if (chkMap.hasAttribute("checked")) chkMap.removeAttribute("checked");}// Switch selected classptabs[0].className = ptabs[0].className.replace("selected", "");ptabs[1].className += " selected";// Set hidden inputvar frm = document.getElementById("syi-form");frm.elements["price.option"].value = "priceType";// Change visibility of controlsdocument.getElementById("syi-price").style.display = "none";document.getElementById("syi-price-type").style.display = "block";// Set selected for "Bieden" option in the select controlvar ptv = frm.elements["price.typeValue"];for (var i=0; i<ptv.options.length; i++){if (ptv.options[i].textContent == "Bieden"){console.log("Found Bieden");ptv.options[i].selected = true;break;}}}if (window.self == window.top) window.setTimeout(switchDisplay, 1000);
发表于:2015-11-01

Maybe a good idea to undisable the price type drop-down in case you need to adjust it manually...

function switchDisplay(){// Select pricingvar ptabs = document.querySelectorAll('#syi-price-tabs a');if (ptabs.length == 0){window.setTimeout(switchDisplay, 500);return;}if (ptabs[1].className.indexOf("selected") > -1) return;// Do not show location on mapvar chkMap = document.getElementById("show-on-map");if (chkMap){chkMap.checked = false;if (chkMap.hasAttribute("checked")) chkMap.removeAttribute("checked");}// Switch selected classptabs[0].className = ptabs[0].className.replace("selected", "");ptabs[1].className += " selected";// Set hidden inputvar frm = document.getElementById("syi-form");frm.elements["price.option"].value = "priceType";// Change visibility of controlsdocument.getElementById("syi-price").style.display = "none";document.getElementById("syi-price-type").style.display = "block";// Set selected for "Bieden" option in the select controlvar ptv = frm.elements["price.typeValue"];for (var i=0; i<ptv.options.length; i++){if (ptv.options[i].textContent == "Bieden"){console.log("Found Bieden");ptv.options[i].selected = true;break;}}if (ptv.hasAttribute("disabled")) ptv.removeAttribute("disabled");}if (window.self == window.top) window.setTimeout(switchDisplay, 1000);
发表于:2015-11-02

Jefferson, You make it look like it's magic, it works flawless

发表于:2015-11-02

Great. Hopefully it will be a while before they change that page again.

发表回复

登录以发表回复。