MicrostockGroup
Agency Based Discussion => Bigstock.com => Topic started by: Semmick Photo on February 27, 2015, 08:39
-
:)
Sean, could you quickly write a script that pulls thumbnails on Bigstock? Similar to what yo did for Canva?
http://www.bigstockphoto.com/account/commissions/downloads/ (http://www.bigstockphoto.com/account/commissions/downloads/)
If you dont have an account and need page source code, let me know.
If you have no time, no problem !
Thanks for considering.
-
I don't have an account there, so it would be really hard. The script isn't too insane though. With a little time, you could probably tweak it. It helps to have firebug so you can find the objects on the page the various things are in.
-
can you quickly give me a foot rub too?
;)
kidding. well... sort of ::)
-
Just curious, why pull thumbnails?
-
Just curious, why pull thumbnails?
To see the sold images without having to click on the image links. That's my guess.
-
I don't have an account there, so it would be really hard. The script isn't too insane though. With a little time, you could probably tweak it. It helps to have firebug so you can find the objects on the page the various things are in.
I have never coded before, but I will look at it to see if I can find anything that makes sense to me and change it. LOL
thanks,
-
Ok, so under the function showThumbs, the first section grabs all the links on the page with the document.links function. It then steps through them to find all the ones that match "media", since each file in the list on the page is linked to like this:
href="/media/MABDFyKV0GQ"
And it puts a reference to each of the link objects into an array - linkObjs. So, you need to change that to pick out the image details page links. The next bit from table through label.setAttribute just makes a new header column for the table, so you need to figure out how to find that area of the document. I know the table has the className of "list" and is the only one with that class, so it's easy to find.
Then the
ajaxStream[0].makeRequest(myDataUrl, linkObjs[j], addThumbnailImage);
kicks off the call to each image details page, with the url to the page, a reference to the link object on the sales page, and the function to do when the call is finished.
Once the ajax finishes its magic, it runs the addThumbnailImage function, giving it all the source from the called page, and the "elementToChange" which is the reference to the link object. It then grabs all the images on the called page with div.getElementsByTagName('img'); and steps through them one by one to see if their .id attribute is "mainImage" . The rest just takes the linkObject reference from before, steps up into the table cell it is in, then up into the table row, and adds a new cell at the end. Into that goes a created image pointing to the thumbnail. The big image on the image details page is like:
https://d117r1wt3t6ahr.cloudfront.net/MABDFyKV0GQ/1/screen.jpg
And I found that the thumbnail is:
https://d117r1wt3t6ahr.cloudfront.net/MABDFyKV0GQ/1/thumbnail.jpg
So, I search and replace on the img.src string to switch to the thumb.
So, all those bits need to change based on the BS pages. It shouldn't be hard if you go step by step.
-
Cheers Sean, appreciated. If I have a result I will post here, if not, as well. Haha.
-
Sean, been looking at this, but I think there is a challenge. You are referring to this
under the function showThumbs, the first section grabs all the links on the page with the document.links function. It then steps through them to find all the ones that match "media", since each file in the list on the page is linked to like this:
href="/media/MABDFyKV0GQ"
So when I check the details for the BS image it seems that they generate a unique link for every image. Not sure how to pull this into the script.
Image-xxxxxxxxx
-
You should be able to match on that. Just change:
if (str.match(/media/g))
to
if (str.match(/image-/g))
-
Ok cool, I changed that now. and I managed to get the Thumb in the list. But the thumbs are not showing. I thin I need to change something for it to pull the thumb in there.
-
Ok, I fixed it. YES !!!!!!!
I forgot to change the function addThumbnailImage
Whoop
-
Tah dah!
-
Semmick Photo said that he will post his code if he makes it work. Then he made it work but he didn't post the code. Very nice...
I'm not a coder so I can't follow Sean Locke's instructions. I tried to edit Sean Locke's script for the thumbnails on Canva but without success. Here is his script:
// ==UserScript==
// @name CV_showThumbnail
// @namespace canva
// @include [url]https://www.canva.com/sales[/url]*
// @version 1
// @grant none
// ==/UserScript==
function showThumbs() {
var linkObjs = [];
for (var j= 0;j<document.links.length;j++)
if (document.links[j].hostname===location.hostname) {
str = document.links[j].href;
if (str.match(/media/g))
linkObjs.push(document.links[j]);
}
ajaxStream = new Array();
table = document.getElementsByClassName('list')[0];
thead = table.getElementsByTagName("tr")[0];
label = document.createElement('th');
thead.appendChild(label);
label.innerHTML = "Thumb";
label.setAttribute('width', "60px");
for (var j= 0;j<linkObjs.length;j++){
myDataUrl = (linkObjs[j].href);
// make a new ajax object
ajaxStream[0] = new ajaxObj();
// pass the url from the 'a' object in the child node, and the linkObj
ajaxStream[0].makeRequest(myDataUrl, linkObjs[j], addThumbnailImage);
}
tcell = table.getElementsByTagName("td");
for (var j= 0;j<tcell.length;j++){
if (tcell[j].innerHTML == " Multi Use ") {
tcell[j].style.backgroundColor = "#bbffbb";
}
}
}
function addThumbnailImage(text, status, elementToChange) {
if (text == "") return;
div=document.createElement('div');
div.innerHTML=text;
var imgs = div.getElementsByTagName('img');
for (var j= 0;j<imgs.length;j++) {
if(imgs[j].id == "mainImage") {
tr = elementToChange.parentNode.parentNode;
td = document.createElement('td');
td.setAttribute('width', "60px");
tr.appendChild(td);
img = document.createElement('img');
img.setAttribute('width', "60px");
imgSrc = imgs[j].src.replace("screen","thumbnail");
img.setAttribute('src', imgSrc);
td.appendChild(img);
return;
}
}
}
window.onload = showThumbs();
function ajaxObj() {
this.requestObject;
this.elementToChange;
this.makeRequest = function(url, elementToChange, onResponse) {
// trying to stop weird exception
if ((url=="") || (url==null)) {
if (elementToChange)
elementToChange.innerHTML = ("<center>N/A | N/A</center>");
return;
}
if (window.XMLHttpRequest) { // Does this browser have an XMLHttpRequest object?
this.requestObject=new XMLHttpRequest(); // Yes -- initialize it.
} else { // No, try to initialize it IE style
this.requestObject=new ActiveXObject("Microsoft.XMLHTTP"); // Wheee, ActiveX, how do we format c: again?
} // End setup Ajax.
if (this.requestObject==null) { // If we couldn't initialize Ajax...
alert("Your browser doesn't support AJAX."); // Sorry msg.
return false; // Return false, couldn't set up ajax
}
this.requestObject.onreadystatechange = function() { // When the browser has the request info..
switch (this.readyState) {
case 1:
// if (elementToChange)
// elementToChange.innerHTML = ("Starting");
break;
case 2:
// if (elementToChange)
// elementToChange.innerHTML = ("Requesting");
break;
case 3:
// if (elementToChange)
// elementToChange.innerHTML = ("Processing");
break;
default:
onResponse(this.responseText, this.readyState, elementToChange); // Pass the response to our processing function
}
}
this.requestObject.open("GET",url,true);
this.requestObject.send(null);
}
}
So can somebody make the script for BS and share it here?
-
Don't bother with Script for BS. You won't have any sales there.
-
Don't bother with Script for BS. You won't have any sales there.
That is absolutely true
+1
-
It looks like Canva has a new layout and broke the script. I'll look at it when I have the time.
-
It looks like Canva has a new layout and broke the script. I'll look at it when I have the time.
Sean, they're now making a new contributors dashboard, don't waste your time with this.
-
Oh yeah, that's right. We must be in the middle of the makeover. Don't like not seeing the thumbs.
-
Oh yeah, that's right. We must be in the middle of the makeover. Don't like not seeing the thumbs.
Maybe you should make a new script. Because who knows how long is this makeover going to take, and we do need to see the thumbnails.