Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name DA Conglomerator
- // @namespace http://lulz.net/
- // @version 1.5.4
- // @description Extracts all submissions from a DeviantArt gallery and displays them as a list of links in a new window. A button "Conglomerate" is inserted into the galery page which activates the script. Checkboxes allow to set specific options for conglomeration. See the tooltip info (move mouse cursor onto the checkboxes) for further explanation of the options. Install guide, updates, changelog and other scripts @ http://pastebin.com/u/lulzScript
- //
- // @include http*://*.deviantart.com/*/gallery/*
- // @include http*://*.deviantart.com/*/art/*
- //
- // @run-at document-start
- // @grant unsafeWindow
- // @grant GM_xmlhttpRequest
- // ==/UserScript==
- //Some constants
- //Default is up to 3 retries for a page to load.
- var congRetries = 3;
- //DA only shows 24 Images per page. This is a fixed value by DA for nonpaid accounts and cannot be changed as of now.
- //Other values will leave out images.
- var daImgsPerPage = 24;
- //Size of the thumbnails in pixels;
- var thumbnailSize = 150;
- //When each request either loaded or gave an error, the rCount should be back at 0.
- //Pending downlaods lead to rCount > 0
- function checkIfDone(gsrc)
- {
- if (rCount[gsrc] == 0)
- lStatus[gsrc].innerHTML = '<b> Done!</b>';
- }
- //Function called when the "GET" request was successful.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the loaded page
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onRetFlashURL (gsrc, req, sCount, lElement)
- {
- var URLFound = false;
- //Get the Flash URL from the response text and insert it into the conglomerator window
- var embed = req.responseText.match(/<embed [^>]*?>/);
- if (embed)
- {
- var fURL = embed[0].match(/src=\"([^\"]*?)\"/);
- if (fURL)
- URLFound = true;
- }
- if ( URLFound )
- congSetLineElement (lElement, fURL[1]);
- else
- lElement[1].innerHTML = '<b>[Error determining Flash URL]</b>';
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Function called when the "GET" request failed.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the failed request
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onRetFlashURLErr (gsrc, req, sCount, lElement)
- {
- //If the "HEAD" request failed, show message in the conglomerator window
- lElement[1].innerHTML = '<b>[Error determining Flash URL]</b>';
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Send a "GET" request to get a page with the embed-code of the flash object from which the URL to the swf can be extracted
- //gsrc = index for gallery/scraps source
- //url = URL of a temporary DA link.
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- //retry = counter that indicates the current number of retries.
- //After [congRetries] failed retries, the function fails.
- function retFlashURL (gsrc, url, sCount, lElement, retry)
- {
- var req = GM_xmlhttpRequest
- (
- {
- url: url,
- method: "GET",
- onreadystatechange: function (req)
- {
- if (req.readyState == 4)
- {
- if ( (req.status >= 200) && (req.status < 400) )
- //If response was sucessfully loaded
- onRetFlashURL (gsrc, req, sCount, lElement);
- else
- {
- //On error retry up to [congRetries] times. Otherwise call error handler.
- if ( retry < congRetries )
- retFlashURL (gsrc, url, sCount, lElement, retry+1);
- else
- onRetFlashURLErr (gsrc, req, sCount, lElement);
- }
- }
- }
- }
- );
- }
- //Function called when the "HEAD" request was successfully.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the loaded page
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onRetFinalURL (gsrc, req, sCount, lElement)
- {
- //Get the final URL from the "loaction" Header and insert it into the conglomerator window
- var loc = req.finalUrl;
- congSetLineElement (lElement, loc);
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Function called when the "HEAD" request failed.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the failed request
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onRetFinalURLErr (gsrc, req, sCount, lElement, ourl)
- {
- //If the "HEAD" request failed, show message in the conglomerator window
- lElement[1].innerHTML = '<b>[Error determining final URL]</b>';
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Send a "HEAD" request to get a response with the actual location from the temporary link
- //gsrc = index for gallery/scraps source
- //url = URL of a temporary DA link.
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- //retry = counter that indicates the current number of retries.
- //After [congRetries] failed retries, the function fails.
- function retFinalURL (gsrc, url, sCount, lElement, retry)
- {
- var req = GM_xmlhttpRequest
- (
- {
- url: url,
- method: "HEAD",
- onreadystatechange: function (req)
- {
- if (req.readyState == 4)
- {
- if ( ((req.status >= 400) && (req.finalURL != url)) || (req.status >= 200) && (req.status < 400) )
- onRetFinalURL (gsrc, req, sCount, lElement);
- else
- {
- //On error retry up to [congRetries] times. Otherwise call error handler.
- if ( retry < congRetries )
- retFinalURL (gsrc, url, sCount, lElement, retry+1);
- else
- onRetFinalURLErr (gsrc, req, sCount, lElement, url);
- }
- }
- }
- }
- );
- }
- function checkForVideoContent (req)
- {
- //Find DA movie player tag
- var daFilmPlayer = req.responseText.match(/<div *class=\"da-film-player[^>]*?>/i);
- if ( daFilmPlayer )
- {
- //Global match for all available movie qualities
- var playerSources = daFilmPlayer[0].match(/"src":"[^]*?"/ig);
- if ( playerSources )
- {
- //Get last match (should be the best quality), remove backslashes and extract URL
- var submURL = playerSources[playerSources.length-1].replace (/\\/g, '').match(/"src":"([^]*?)"/i);
- return([submURL[1]]);
- }
- }
- //If nothing was found, return null
- return (null);
- }
- function checkForDownloadButton (req)
- {
- var submURL = req.responseText.match(/<a *class=\"[^\"]*?dev-page-download[^\"]*?\"[^]*?href=\"([^\"]*?)\"/i);
- if (submURL)
- return ([submURL[1].replace(/&/, '&')]);
- //If nothing was found, return null
- return (null);
- }
- function checkForImageViewer (req)
- {
- var submURL1 = req.responseText.match(/<img [^>]*?class=\" *dev-content-full *\"[^>]*?>/i);
- if (!submURL1)
- var submURL1 = req.responseText.match(/<img [^>]*?class=\" *dev-content-normal *\"[^>]*?>/i);
- if (submURL1)
- {
- var submURL2 = submURL1[0].match(/src=\"([^\"]*?)\"/i);
- if (submURL2)
- return ([submURL2[1]]);
- }
- //If nothing was found, return null
- return (null);
- }
- function checkForFlashContent (req)
- {
- //Find the sandbox-link of the flash content
- var sbflashURL = req.responseText.match(/<iframe *class=\"flashtime\"[^]*?src=\"([^\"]*?)\"[^>]*?/i);
- if ( sbflashURL )
- return ([sbflashURL[1]]);
- //If nothing was found, return null
- return (null);
- }
- function checkForEmbeddedImages (req)
- {
- var submURLs_ = req.responseText.match(/class=\"[^\"]*?embedded-deviation[^\"]*?\"[^]*?data-fullview=\"[^\"]*?\"/ig);
- if ( submURLs_ )
- {
- var submURLs = [];
- for (var i=0; i < submURLs_.length; i++)
- {
- var submURL = submURLs_[i].match(/data-fullview=\"([^\"]*)\"/);
- if ( submURL )
- submURLs.push(submURL[1]);
- }
- if (submURLs.length > 0)
- return (submURLs);
- }
- //If nothing was found, return null
- return (null);
- }
- //Function called when a submission page was successfully loaded.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the loaded page
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onSubm (gsrc, req, sCount, lElement)
- {
- var submURLStr = null;
- //Get the submission URL from the page source
- //Check for movie first
- //If submission is a movie, don't use download links, but extract URL(s) from DA movie viewer
- submURLStr = checkForVideoContent (req);
- //If no movie try the download button
- if ( !submURLStr )
- submURLStr = checkForDownloadButton (req);
- //If no download button try image viewer
- if ( !submURLStr )
- submURLStr = checkForImageViewer (req);
- //If no image viewer try flash content
- var flash = false;
- if ( !submURLStr )
- {
- submURLStr = checkForFlashContent (req);
- flash = true;
- }
- //If no flash content try embedded images in literature
- if ( !submURLStr )
- submURLStr = checkForEmbeddedImages (req);
- //if content is found, insert link into conglomerator window
- if ( submURLStr )
- {
- //If the content is Flash, the actual URL of the swf has to be extracted from the response text of another request.
- if (flash)
- {
- //Increase request counter for additional request.
- rCount[gsrc]++;
- setTimeout (retFlashURL, 0, gsrc, submURLStr[0], sCount, lElement, 0);
- }
- else
- {
- //If option is set to retieve the final URLs from the temporary ones first, do so
- if ( retrieveFinalURL )
- {
- //Increase request counter for each additional request.
- rCount[gsrc]++;
- setTimeout(retFinalURL, 0, gsrc, submURLStr[0], sCount, lElement, 0);
- }
- else
- {
- //Otherwise insert the temporary links (which will expire after a few mintes)
- congSetLineElement(lElement, submURLStr[0]);
- }
- }
- var prevLElement = lElement;
- for (var i=1; i < submURLStr.length; i++)
- {
- var tempLElement = congCreateNewLineElement(gsrc, '', prevLElement, lElement[3] + '.' + (i+1));
- congSetLineElement(tempLElement, submURLStr[i]);
- //If the content is Flash, the actual URL of the swf has to be extracted from the response text of another request.
- if (flash)
- {
- //Increase request counter for each additional request.
- rCount[gsrc]++;
- setTimeout (retFlashURL, 0, gsrc, submURLStr[0], sCount, lElement, 0);
- }
- else
- {
- //If option is set to retieve the final URLs from the temporary ones first, do so
- if (retrieveFinalURL)
- {
- //Increase request counter for each additional request.
- rCount[gsrc]++;
- setTimeout(retFinalURL, 0, gsrc, submURLStr[i], sCount, tempLElement, 0);
- }
- else
- {
- //Otherwise insert the temporary links (which will expire after a few mintes)
- congSetLineElement(tempLElement, submURLStr[i]);
- }
- }
- prevLElement = tempLElement;
- }
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- else
- {
- //If theres is no content found, this is either probably mature content and the user
- //is either not logged in or the account's age setting ("Date of Birth") does not
- //allow mature content. Or it is unsupported/special content like stories/writing
- //that cannot be downloaded.
- lElement[1].innerHTML = '<b>[No content link found in submission page - Not logged in? Mature content disabled? Unsupported/special content?]</b>';
- //Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- }
- //Function called when a submission page failed to load.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the failed page
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- function onSubmErr (gsrc, req, sCount, lElement)
- {
- //Page could not be loaded. Display Error message.
- lElement[1].innerHTML = '<b>[Error loading submission]</b>';
- //Request finished with error. Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Loads a submission page from the gallery/scraps collection asynchronously.
- //gsrc = index for gallery/scraps source
- //submPageURL = URL of submission page.
- //sCount = submission number within the conglomerator window
- //lElement = reference to the link element in the conglomerator window.
- //retry = counter that indicates the current number of retries.
- //After [congRetries] failed retries, the function fails.
- function getSubm (gsrc, submPageURL, sCount, lElement, retry)
- {
- var req = new XMLHttpRequest();
- //Prepare request with full URL, containing the desired page number
- req.open('GET', submPageURL, true);
- //Function to call when loading state of page changes
- req.onreadystatechange = function (evt)
- {
- //Check if page was loaded (or not)
- if (req.readyState == 4)
- {
- if ( (req.status >= 200) && (req.status < 400) )
- //If page was sucessfully loaded
- onSubm (gsrc, req, sCount, lElement);
- else
- {
- //If page failed to load, retry up to [congRetries] times. Otherwise call error handler.
- if ( retry < congRetries )
- getSubm (gsrc, submPageURL, sCount, lElement, retry+1);
- else
- onSubmErr (gsrc, req, sCount, lElement);
- }
- }
- };
- //Sends request and starts loading of the page.
- req.send(null);
- }
- function congCreateNewLineElement(gsrc, thumbURL, insertAfter, lineNoTxt)
- {
- var span1 = congLinkWin[gsrc].document.createElement('span');
- if ( lineNoTxt )
- var lineNo = lineNoTxt;
- else
- var lineNo = sCount[gsrc].toString();
- span1.innerHTML = '<br><b>' + lineNo + ': </b>';
- var span2 = congLinkWin[gsrc].document.createElement('span');
- var linkObj = congLinkWin[gsrc].document.createElement('a');
- //This attribute will open a new page if the link is clicked in the conglomerator window.
- linkObj.setAttribute('target', '_blank');
- if ( thumbURL )
- {
- var thumbnail = congLinkWin[gsrc].document.createElement('img');
- thumbnail.setAttribute('src', thumbURL);
- thumbnail.setAttribute('height', thumbnailSize + 'px');
- span1.insertBefore(thumbnail, null); //lElement[0] = span
- thumbnail.style.verticalAlign = "middle";
- thumbnail.style.marginRight = '10px';
- }
- span1.insertBefore(span2, null);
- var insertAt = null;
- if ( insertAfter )
- insertAt = insertAfter[0].nextSibling;
- //Add the newly created line element to the conglomerator window
- congLinkWin[gsrc].document.body.insertBefore(span1, insertAt);
- return ( [span1, span2, linkObj, lineNo] );
- }
- function congSetLineElement(lElement, sURL)
- {
- //Insert download link into link list
- //Link displayed as text
- lElement[2].innerHTML = sURL;
- //Also set the href attribut, to make the link clickable
- lElement[2].setAttribute('href', sURL);
- lElement[1].innerHTML = '';
- lElement[0].insertBefore(lElement[2], null);
- }
- function fixProtocol (URL)
- {
- return (daProtocol + URL.replace(/https/, '').replace(/http/, ''));
- }
- //Function called when a submission list page was successfully loaded.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the loaded page
- //no = number of loaded page
- function onSubmList (gsrc, req, no)
- {
- //Extract all submission IDs
- var PDstart = req.responseText.search('data-sigil=\"gallery-torpedo\"');
- var PDend = PDstart + req.responseText.substr(PDstart).search('id=\"gmi-CCommentMaster\"');
- var newResponseText = req.responseText.substring(PDstart, PDend);
- //Find thumbnail elements with links to the full image
- //var rawSubmLinks = newResponseText.match(/<a *class=[^>]*?title=[^>]*?(?:data-super-img=[^>]*?|)>/gi);
- var rawSubmLinks = newResponseText.match(/<span[^>]+?class=\"thumb[^]*?<\/span>/gi);
- //Continue as long as there are thumbnail elememts found
- if ( rawSubmLinks )
- {
- //Display page number
- var span = congLinkWin[gsrc].document.createElement('span');
- span.innerHTML = '<br></br><b>Page ' + no + '</b><br>';
- congLinkWin[gsrc].document.body.insertBefore(span, null);
- //Iterate through all found thumbnails
- for (var i=0; i < rawSubmLinks.length; i++)
- {
- //Create a new line element for the submission in the conglomerator window
- var thumbURLStr = null;
- //Optionally get thumbnail URL and insert thumbnail in conglomerator window
- if (showThumbnails)
- {
- var thumbURL = rawSubmLinks[i].match(/<img[^]*?src=\"([^\"]*?)\"[^>]*?>/);
- if ( thumbURL )
- thumbURLStr = thumbURL[1];
- }
- var lElement = congCreateNewLineElement(gsrc, thumbURLStr, null, null);
- //If checkbox is checked, only get links fromn the submission page.
- if ( submpOnly )
- submURL = null;
- else
- {
- //Try to extract the URL from "data-super-full-img"
- var submURL = rawSubmLinks[i].match(/data-super-full-img=\"([^\"]*)\"/);
- //If there is no "data-super-full-img" alternatively extract the URL from "data-super-img"
- if ( !submURL )
- var submURL = rawSubmLinks[i].match(/data-super-img=\"([^\"]*)\"/);
- }
- //If either "data-super-full-img" or "data-super-img" was found, create a link in the conglomerator window
- if ( submURL )
- {
- //Insert download link into link list
- congSetLineElement (lElement, submURL[1]);
- }
- //Otherwise it is either locked (mature) content, special content (or both) or the
- //checkbox for conglomeration from the submission page only was checked.
- //In this case try to extract the link from the submission page
- else
- {
- var submPageURL = rawSubmLinks[i].match(/href=\"([^\"]*)\"/);
- if ( submPageURL )
- {
- //Increase request counter
- rCount[gsrc]++;
- //Load submission page asynchronously.
- //function fixProtocol will make sure that the correct protocol is used
- getSubm (gsrc, fixProtocol(submPageURL[1]), sCount[gsrc], lElement, 0);
- lElement[1].innerHTML = '<b>loading...</b>';
- }
- //If there is no link display message in conglomerator window
- else
- lElement[1].innerHTML = '<b>[No submission page link found]</b>';
- }
- //Increase submission counter
- sCount[gsrc]++;
- }
- //Increase request counter
- rCount[gsrc]++;
- //Load next submission list page
- getSubmList (gsrc, no+1, 0);
- }
- else
- {
- //There are no more pages. Display message.
- var span = congLinkWin[gsrc].document.createElement('span');
- span.innerHTML = '<br><br><b>No more pages!<b>';
- congLinkWin[gsrc].document.body.insertBefore(span, null);
- }
- //Request finished successfully. Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Function called when a submission list page failed to load.
- //gsrc = index for gallery/scraps source
- //req = XMLHttpRequest object of the failed page
- //no = number of loaded page
- function onSubmListErr (gsrc, req, no)
- {
- //Page could not be loaded. Display Error message.
- var span = congLinkWin[gsrc].document.createElement('span');
- span.innerHTML = '<br><br><b>Error - cannot load page ' + no + '!<br/>Further conglomeration stoppped.</b>';
- congLinkWin[gsrc].document.body.insertBefore(span, null);
- //Request finished with error. Decrease request counter and check if rCount = 0.
- rCount[gsrc]--;
- checkIfDone(gsrc);
- }
- //Loads a submission list page from the gallery/scraps collection asynchronously.
- //gsrc = index for gallery/scraps source
- //no = Nummer of list page to load
- //retry = counter that indicates the current number of retries.
- //After [congRetries] failed retries, the function fails.
- function getSubmList (gsrc, no, retry)
- {
- var req = new XMLHttpRequest();
- //Prepare request with full URL, containing the desired page number
- req.open('GET', submBaseURL[gsrc] + (no-1) * daImgsPerPage, true);
- //Function to call when loading state of page changes
- req.onreadystatechange = function (evt)
- {
- //Check if page was loaded (or not)
- if (req.readyState == 4)
- {
- if ( (req.status >= 200) && (req.status < 400) )
- //If page was sucessfully loaded
- onSubmList (gsrc, req, no);
- else
- {
- //If page failed to load, retry up to [congRetries] times. Otherwise call error handler.
- if ( retry < congRetries )
- getSubmList (gsrc, no, retry+1);
- else
- onSubmListErr (gsrc, req, no);
- }
- }
- };
- //Sends request and starts loading of the page.
- req.send(null);
- }
- //Global variables:
- //Used in htmlUnescapeURL
- var dummyElement;
- //Base URL of DA, including protocol and subdomain
- var daBaseURL;
- //Used Protocol (http/https)
- var daProtocol;
- //Base URLs of gallery/scraps
- var submBaseURL = [,];
- var submBaseURL = [,];
- //Reference to new link window
- var congLinkWin = [,];
- var congLinkWin = [,];
- //Counter for submission index
- var sCount = [,];
- //Request counter. Used to determine when all submissions are loaded.
- var rCount = [,];
- //Name of DA user whose galery/scraps are being conglomerated
- var daUsername;
- //Reference to status message in link window
- var lStatus = [,];
- var lStatus = [,];
- //State of the congCB checkbox
- var submpOnly;
- //State of the congCB2 checkbox
- var retrieveFinalURL;
- //State of the congCB3 checkbox
- var showThumbnails;
- //Selection of gallery and/or scraps to be conglomerated
- var doCong = [,];
- var ACDummy;
- //Main script function. Called when conglomerator button is clicked
- function congStart(e)
- {
- ACDummy = new AudioContext();
- //Prevents the form's default action for a button
- e.preventDefault();
- //Get state of congCB checkbox
- submpOnly = congCB_fsp[0].checked;
- //Get state of congCB2 checkbox
- retrieveFinalURL = congCB_fu[0].checked;
- //Get state of congCB3 checkbox
- showThumbnails = congCB_st[0].checked;
- //Get state of gallery/scraps selection
- doCong[0] = congCB_g[0].checked;
- doCong[1] = congCB_s[0].checked;
- //Create dummy element used in htmlUnescapeURL function
- dummyElement = document.createElement('span');
- //Get DA base URL (including protocol and a possible subdomain)
- var daBaseURL_ = document.location.href.match(/(([^\/]*):\/\/[^\.]*\.deviantart\.com\/([^\/]*)\/)gallery\//);
- if ( daBaseURL_ )
- {
- daBaseURL = daBaseURL_[1];
- daProtocol = daBaseURL_[2]; //Needed because DA uses mixed http/https content that has to be fixed when fetching the thumbnail page
- daUsername = daBaseURL_[3];
- submBaseURL[0] = daBaseURL + 'gallery/?catpath=%2F&offset=';
- submBaseURL[1] = daBaseURL + 'gallery/?catpath=scraps%2F&offset=';
- //Open new window(s) for extracted submission links
- for (var i=0; i < 2; i++)
- {
- if (doCong[i])
- {
- congLinkWin[i] = unsafeWindow.open();
- if ( congLinkWin[i] )
- {
- //Add title to link window
- var span = congLinkWin[i].document.createElement('span');
- switch (i)
- {
- case 0:
- span.innerHTML = '<b>List of ' + daUsername + '\'s gallery:<b>';
- //Set title of new window
- congLinkWin[0].document.title = 'DA conglomerator - Gallery';
- break;
- case 1:
- span.innerHTML = '<b>List of ' + daUsername + '\'s scraps:<b>';
- //Set title of new window
- congLinkWin[1].document.title = 'DA conglomerator - Scraps';
- break;
- }
- congLinkWin[i].document.body.insertBefore(span, null);
- //Add status message to link Window
- lStatus[i] = congLinkWin[i].document.createElement('span');
- lStatus[i].innerHTML = '<b> Loading...</b>';
- congLinkWin[i].document.body.insertBefore(lStatus[i], null);
- //Reset submission and request counter
- sCount[i] = 1;
- rCount[i] = 1;
- //At this point daBaseURL and submBaseURL both matched correctly.
- //Load first submission list page. Page counter begins at 1
- getSubmList (i, 1, 0);
- }
- }
- }
- }
- }
- function insertButton()
- {
- //Find location of gallery controls
- var gmi = document.getElementById('gmi-GalleryEditor');
- if (gmi)
- {
- var lis = gmi.getElementsByTagName('li');
- for (var i=0; i < lis.length; i++)
- {
- if ( lis[i].getAttribute('class').search(/browse/) == 0 )
- {
- var browsebar = lis[i].parentNode;
- break;
- }
- }
- //If found, insert conglomerator button and checkbox/text
- if ( browsebar )
- {
- //Insert button element and a line break
- browsebar.insertBefore(congButton, null);
- browsebar.insertBefore(document.createElement('br'), null);
- //Insert checkbox elements and a line breaks
- browsebar.insertBefore(congCB_g[1], null);
- browsebar.insertBefore(document.createElement('br'), null);
- browsebar.insertBefore(congCB_s[1], null);
- browsebar.insertBefore(document.createElement('br'), null);
- browsebar.insertBefore(document.createElement('br'), null);
- browsebar.insertBefore(congCB_fsp[1], null);
- browsebar.insertBefore(document.createElement('br'), null);
- browsebar.insertBefore(congCB_fu[1], null);
- browsebar.insertBefore(document.createElement('br'), null);
- browsebar.insertBefore(congCB_st[1], null);
- browsebar.insertBefore(document.createElement('br'), null);
- buttonInserted = true;
- }
- }
- }
- function createCheckBox (checked, text, tooltip)
- {
- var CB = [,];
- //Create checkbox for extracting links from submission page only
- CB[0] = document.createElement('input');
- //Set input type to checkbox
- CB[0].setAttribute('type', 'checkbox');
- //Set default state
- CB[0].checked = checked;
- //Create checkbox text label
- CB[1] = document.createElement('label');
- //Reduce checkbox font size
- CB[1].style.fontSize = '8pt';
- //Set checkbox text
- CB[1].innerHTML = text;
- //Add tooltip info
- CB[1].title = tooltip;
- //insert checkbox into label element
- CB[1].insertBefore(CB[0], CB[1].firstChild);
- return(CB);
- }
- //Flag that is later set to true if button was inserted.
- var buttonInserted = false;
- //Conglomerator button
- //=====================================================
- //Create button for conglomerator script
- var congButton = document.createElement('button');
- //Set button text
- congButton.innerHTML = 'Conglomerate';
- //Set button style to DA style
- congButton.setAttribute('class', 'smbutton');
- //Set function to call on a click
- congButton.addEventListener ('click', congStart, false);
- //Add tooltip info
- congButton.title = 'Extract all submissions from this gallery and display them as a list of links in a new window.';
- //=====================================================
- //Conglomerator checkbox: "from subm. page"
- //=====================================================
- var cToolTip =
- 'Conglomerate links from the actual submission page.\n' +
- 'This takes longer but will always get the links with the highest image quality (eg. from the "Download" button on submission page)\n' +
- 'Otherwise the links are extracted from the thumbnail page, which don\'t always point to the best image quality';
- var congCB_fsp = createCheckBox (true, 'from subm. page', cToolTip);
- //Conglomerator checkbox: "final URL"
- //=====================================================
- var cToolTip =
- 'Retrieve the final download server URLs.\n\n' +
- 'DA creates temporary links to images that will expire after a few minutes.\n' +
- 'If conglomeration takes too long, links may expire before they can be downloaded.\n' +
- 'This option will retrieve the final download server URLs which don\'t expire, but conglomeration is slower because an additinal requests to the server has to be sent for each link.\n\n' +
- 'This option is ignored if option "from subm. page" is not checked.\n\n' +
- 'NOTE:\n' +
- 'If you\'re blocking third-party cookies, add an exception for "deviantart.com" in the browser\'s cookie settings. Otherwise the final URL cannot be retrieved.';
- var congCB_fu = createCheckBox (true, 'final URL', cToolTip);
- //Conglomerator checkbox: "Show thumbnails"
- //=====================================================
- var cToolTip =
- 'Show thumbnails for each link in the conglomerator window';
- var congCB_st = createCheckBox (false, 'Show thumbnails', cToolTip);
- //Conglomerator checkbox: "Gallery"
- //=====================================================
- var cToolTip =
- 'Conglomerate gallery';
- var congCB_g = createCheckBox (true, 'Gallery', cToolTip);
- //Conglomerator checkbox: "Scraps"
- //=====================================================
- var cToolTip =
- 'Conglomerate scraps';
- var congCB_s = createCheckBox (true, 'Scraps', cToolTip);
- //=====================================================
- //Try to insert button into page if page is already available at this time
- insertButton();
- //Function onDCL is called when DOM tree has completely been loaded.
- //This is the savest way to start a script.
- document.addEventListener ('DOMContentLoaded',
- function onDCL(e)
- {
- //If the button wasn't inserted before because the page wasn't
- //available at that time, it will be inserted now.
- if ( !buttonInserted )
- insertButton();
- }, false
- );
- //Additional, faster way to insert and display the conglomerator button.
- //Inernal scripts on the page sometimes seem to block the DOMContentLoaded event until they have executed completely.
- //This code will insert the button as soon as (but before) an internal script is called
- document.addEventListener ('beforescriptexecute',
- function onDCL(e)
- {
- //Try to insert button, if it hasn't been inserted yet.
- if ( !buttonInserted )
- insertButton();
- //Check if the button was inserted somehow (either by this function or by the DOMContentLoaded event listener above)
- if (buttonInserted)
- {
- //Remove this event listener again if button was inserted successfully.
- document.removeEventListener ('beforescriptexecute', onDCL, false);
- }
- }, false
- );
Advertisement
Add Comment
Please, Sign In to add comment