Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Greasemonkey

Name: Anonymous 2009-03-14 0:01

Hey /prog/

What do I have to change about this greasemonkey script so that when I go to an imagefap page, the thing acutally finishes loading:
http://userscripts.org/scripts/show/15603

I tried removing the timeout at the bottom but then it'll just stop working.

Help me experts.

Name: Anonymous 2009-03-14 1:50

God I hate you faggots.
Why do I come here for help.

Name: Anonymous 2009-03-14 2:34

>>2
If it was something simple I would help you with some trolling sprinkled on the side. I will not however, install greasemonkey, download and install the listed script, and then proceed to go to imagefap- where I can test and fix the script to no personal benefit whatsoever. Post the section of javascript that you think doesn't work, and perhaps I will be able to say why but asking other people to do everyhing else for you is against the ideas of progress and learning, aswell as being both unscientific and ultimately destructive.
----
-The Sussman

Name: Anonymous 2009-03-14 2:58

Have you tried reading SIGMS?

Name: Anonymous 2009-03-14 3:09

>>3
Well here's the script, I tried deleting the set timeout portion on the bottom but it breaks everything.

// set to false to hide thumbs
var showThumbs=false;
// number of pictures to show per page,
// set to -1 to disable paging but big galleries (200+ images) will really eat memory.
var perPage=20;

var title='';
var desc;
var head='';
var discovered=new Array();
var favURL;

// current page (starting from 0)
var currPage;
// number of pages (starting from 1)
var numPages;
// url without &page=X
var baseURL;
// number of images
var num;

function addPage(doc) {
    var pageIdx=document.location.href.indexOf('&pg=');
    if (pageIdx==-1) {
        currPage=0;
        baseURL=document.location.href;
    } else {
        var pgStr=document.location.href.substring(pageIdx+4);
        baseURL=document.location.href.substring(0,pageIdx);
//        alert('pgStr:'+pgStr);
        currPage=eval(pgStr);
    }
    var first=perPage*currPage;
    var last=first+perPage;

//    alert('currPage:'+currPage+' first:'+first+' last:'+last);
  // collect images
      var obj = document.getElementsByTagName('img');
      var url_regex = /(.*\/images\/thumb\/.*)\/(.*)$/i;
      var count=0;
      num=0;
    for(var i = 0 ; i < obj.length; i++) {
          if (url_regex.test(obj[i].src)) {
              if ((count>=first&&count<last)) {
                  var temp = url_regex.exec(obj[i].src);
 
              var src=temp[0].replace(/thumb/, 'full');
              discovered[discovered.length]=escape(src);
              }
              count++;
              num++;
           
           
      //+':'+obj[i].width+'x'+obj[i].height;
//      alert('src: '+src);
        }
    }
    numPages=Math.ceil(num/perPage);
//    alert('num: '+num+' pages: '+numPages);



} // add page

function doIt() {
    addPage(document,true);


  var newBody = ""

    var pager='';
    if (perPage!=-1 && numPages>1) {
        pager="<div id='pager'>";
       
        for (var i=0;i<numPages;i++) {
            if (i==currPage)
                pager+="<b style='margin-left: 5px'>"+(i+1)+"</b>";
            else
                pager+="<a style='margin-left: 5px' href='"+baseURL+"&pg="+i+"'>"+(i+1)+"</a>";
        }
        pager+="</div>"
    }

  var ends="<table cellpadding='0' cellspacing='0' width='100%'>"+
  "<form action='/gallery.php' method='POST'>"+
  "<tr><td width='100%' valign='top'>"+
  title+"</td>"+
  "<td width='100%' valign='top' align='center'>";
    if (perPage!=-1 && numPages>1)
    ends+=
  ends+="</td>"+
  "<td width='100%' align='right' valign='top' width='300'>"+
    "</td></tr></form></table>";
   
    newBody+=ends+"<p/>";
  newBody+="<center id=\"top\">";

  if (desc)
    newBody+=desc+"<p/>";
 
  if (showThumbs) {
    newBody+"<div style=\"margin: 30px\">";+
  "<tr><td width='100%' valign='top'>"
    for (var i=0;i<discovered.length;)  {
      var j=0;
      for (;j<6&&i+j<discovered.length;j++) {
        var disc=unescape(discovered[i+j]);
        var src=disc.replace(/full/, 'thumb');
            newBody+="<img style=\"margin: 5px\" src=\"" +src+ "\"/></a>";
//              newBody+="<img style=\"border: 0px; margin: 10px\" src=\"" +src+ "\"/>";
          }
          i=i+j;
      }
      newBody+="</div><p/><hr/>";
    }
    newBody+="<p/>";

  for (var i=0;i<discovered.length;i++)
        newBody+="<img id=\"img"+i+"\" src=\"" +unescape(discovered[i])+ "\"/></a><p />";



  newBody+="<p/>"+ends;
  newBody+="</center>";
  newBody += "</body></html>";
  document.write(newBody);
}




// if referring to a gallery, not a search, etc.
//if (document.location.href.indexOf('gid=')!=-1)  {
  // if url doesn't have a &view= in it, redirect to url+'&view=2', which shows all thumbs on one page
  // thanks to whitewaterfap
  if (document.location.href.indexOf('view=')==-1) {
        if (document.location.href.indexOf('?')==-1)
        document.location.href=document.location.href+'?view=2';
        else
        document.location.href=document.location.href+'&view=2';
  } else {
    setTimeout(function() { doIt(); },1000);
  }
//}

Name: Anonymous 2009-03-14 3:29

>>5
Looks awfully similar to this snippet from that Python thread.

#Web designer
def factorial(x):
    #-------------------------------------------------
    #--- Code snippet from The Math Vault          ---
    #--- Calculate factorial (C) Arthur Smith 1999 ---
    #-------------------------------------------------
    result = str(1)
    i = 1 #Thanks Adam
    while i <= x:
        #result = result * i  #It's faster to use *=
        #result = str(result * result + i)
           #result = int(result *= i) #??????
        result str(int(result) * i)
        #result = int(str(result) * i)
        i = i + 1
    return result
print factorial(6)

Name: Anonymous 2009-03-14 4:50

>>5
Thanks, an unformatted script pasted in here is going to help tonnes. What is the exact problem that is happening, how do you produce it is an error produced?

Name: Anonymous 2009-03-14 5:15

>>5
I wrote this in about ten minutes because I was bored. You might or might not find it usable, but I don't really care either way. This is SPARTA after all.

// ==UserScript==
// @include http://*.imagefap.com/gallery*;
// @name Imagefap Expander
// @author Anonymous
// @version 2009-03-14
// @description Enjoy your load times.
// ==/UserScript==

(function () {
// Don't change this, too lazy to actually code paging.
// Do it yourself if you actually need it.
const IMAGES_PER_PAGE = 0;

// Make sure the current location is gallery.php?...&view=2
var match = window.location.pathname.match(/\/gallery\/(\d+)/);
if (match) {
    window.location.replace("http://" + window.location.hostname +
        "/gallery.php?gid=" + match[1] + "&view=2");
}
match = window.location.search.match(/view=[^2]/)
if (match) {
    window.location.replace(
        window.location.href.replace(/view=[^2]/, "view=2"));
}

function constructImagePage(images, pageIndex) {
    var fragment = document.createDocumentFragment();
    var firstImgIdx = IMAGES_PER_PAGE > 0 ? pageIndex * IMAGES_PER_PAGE : 0;
    var lastImgIdx = IMAGES_PER_PAGE > 0 ?
        Math.min((pageIndex * IMAGES_PER_PAGE) + IMAGES_PER_PAGE,
                images.snapshotLength) : images.snapshotLength;

    // Add images
    for (var i = firstImgIdx; i < lastImgIdx; ++i) {
        var img = document.createElement("img");
        var oldImg = images.snapshotItem(i);
        img.setAttribute("src", oldImg.src.replace("/thumb/", "/full/"));
        fragment.appendChild(img);
        fragment.appendChild(document.createElement("br"));
    }
    return fragment;
}

// Find all images
var images = document.evaluate("//a[starts-with(@href, '/image.php')]/img",
    document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

// Replace body will just the images
while (document.body.hasChildNodes())
    document.body.removeChild(document.body.firstChild);
document.body.appendChild(constructImagePage(images, 0));

})();

Name: Anonymous 2009-03-14 5:18

>>8
Oh, and make that // @include http://*imagefap.com/gallery*; instead.

Name: Anonymous 2009-03-14 5:18

>>9
AND REMOVE THAT GOD-DAMNED SEMICOLON DAMN I AM RETARDED.

Name: Anonymous 2009-03-14 7:06

>>8-10

FUCK YES YOU ARE THE GREATEST AND JUST RELIEVED DAYS OF STRESS FROM MY BEING

I love you anon.

Name: Anonymous 2009-03-14 10:03

>>8

Anon delivered.

Awesome.

Thank you.

Name: Anonymous 2009-03-14 10:21

Test: // @include http://*imagefap.com/gallery*; end test.

Test: [code]// @include http://*imagefap.com/gallery*[/code] end test.

Name: Anonymous 2009-03-14 10:22

It's as I thought. Shiichan sometimes inserts semicolons after URLs.

Name: Anonymous 2009-03-14 10:28

>>14
Thank God. I thought I've fucked up majorly twice.

Name: Anonymous 2009-03-14 23:09

>>8

How would one modify that code to auto expand images on Danbooru?

Here are some examples:

Tag gallery URL
http://danbooru.donmai.us/post/index?tags=0_raiser

Thumbnail URL
http://danbooru.donmai.us/data/preview/96883c13eaf31ea76519ebf15ce377ba.jpg

Full image URL
http://danbooru.donmai.us/data/96883c13eaf31ea76519ebf15ce377ba.jpg

The full images use the same filename as the thumbnail, they are just in /data/, not /data/preview/

The source code of the tag gallery mentions that filename on two lines. In a thumbnail line (and also in a Post.register line):

<span class="thumb" id="p410401"><a href="/post/show/410401/00_gundam-00_raiser-0_raiser-3d-dual_wield-gun-gun" onclick="return PostModeMenu.click(410401)"><img src="http://danbooru.donmai.us/data/preview/96883c13eaf31ea76519ebf15ce377ba.jpg" alt="*

I tried removing the gallery "match" portion of the imagefap expander code, and also

Changing the code to this
img.setAttribute("src", oldImg.src.replace("/preview/", "/"));

And changing the code to this
var images = document.evaluate("//span[starts-with(@class, 'thumb')]/img",

But I can't get it to work. Any ideas?

Name: Anonymous 2009-03-15 4:00

>>16
There should be an <a> tag between <span> and <img>, which would explain why the expression returned no images.

In any case, instead of using the above script, give this one a try.

// ==UserScript==
// @include http://danbooru.donmai.us/post*;
// @name Danbooru Expander
// @author Anonymous
// @version 2009-03-15
// @description Enjoy your load times. (absurdres...)
// ==/UserScript==

(function () {
// Find registered posts (JavaScript haxx)
var regexp = /Post.register\(\{(.+?)\}\)/g;
var imageUrls = Object();
var match = regexp.exec(document.body.innerHTML);
while (match) {
    eval("var arr = {" + match[1] + "};");
    imageUrls[arr["preview_url"]] = arr["file_url"];
    match = regexp.exec(document.body.innerHTML);
}

var images = document.evaluate("//span[@class='thumb']/a/img",
    document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);

var img = images.iterateNext();
while (img) {
    img.removeAttribute("width");
    img.removeAttribute("height");
    img.parentNode.parentNode.style.height = "auto";
    img.parentNode.parentNode.style.width = "auto";
    img.setAttribute("src", imageUrls[img.getAttribute("src")]);
    img = images.iterateNext();
}   
})();


Oh, and remove the semicolon after @include ... in case Shiichan adds one again. I'M NOT FALLING FOR IT A SECOND TIME!

Name: Anonymous 2009-03-15 7:23

>>17

Thank you! You're a king. Although for me that new script only shows the first picture in full resolution.

But I used this line from the new script along with the imagefap code
var images = document.evaluate("//span[@class='thumb']/a/img",

and it shows every fullres pic (except one) on a tag gallery I checked.

I guess the pic that didn't show had a .gif extension, but the thumbnail had a .jpg extension. I think all thumbs are JPGs, so only fullres JPGs are shown.

Now I see why you scrape Post.register

Name: Anonymous 2009-03-15 7:44

>>18
I see. Probably due to setting the result type to XPathResult.UNORDERED_NODE_ITERATOR_TYPE, which is invalidated after a modification to the DOM tree. I originally tested the script with Opera (don't have Firefox), so I thought it was fine.

You might have more luck with a loop like this:
var images = document.evaluate("//span[@class='thumb']/a/img",
    document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < images.snapshotLength; ++i) {
    var img = images.snapshotItem(i);
    img.removeAttribute("width");
    img.removeAttribute("height");
    img.parentNode.parentNode.style.height = "auto";
    img.parentNode.parentNode.style.width = "auto";
    img.setAttribute("src", imageUrls[img.getAttribute("src")]);
}

Name: Anonymous 2009-03-15 10:32

>>19

Fantastic. Thank you so much. Here's the full working Danbooru Expander script.

// ==UserScript==
// @include http://danbooru.donmai.us/post*
// @name Danbooru Expander
// @author Anonymous
// @version 2009-03-15
// @description Enjoy your load times. (absurdres...)
// ==/UserScript==

(function () {
// Find registered posts (JavaScript haxx)
var regexp = /Post.register\(\{(.+?)\}\)/g;
var imageUrls = Object();
var match = regexp.exec(document.body.innerHTML);
while (match) {
    eval("var arr = {" + match[1] + "};");
    imageUrls[arr["preview_url"]] = arr["file_url"];
    match = regexp.exec(document.body.innerHTML);
}

var images = document.evaluate("//span[@class='thumb']/a/img",
    document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < images.snapshotLength; ++i) {
    var img = images.snapshotItem(i);
    img.removeAttribute("width");
    img.removeAttribute("height");
    img.parentNode.parentNode.style.height = "auto";
    img.parentNode.parentNode.style.width = "auto";
    img.setAttribute("src", imageUrls[img.getAttribute("src")]);
}
})();

Name: Anonymous 2009-03-15 11:21

>>20
You are welcome.

Name: Anonymous 2010-07-19 15:48

I tried using this and it didn't work. Maybe it's because it's old already. Any chance of there being an updated version or something?

Name: Anonymous 2010-07-19 16:20

>>22
Please think of the bandwidth bills of poor danbooru.

Name: Anonymous 2010-07-19 16:27

>>23

I can be compassionate, but my penis can not. I am sorry.

Name: Anonymous 2011-02-02 22:42

Name: Anonymous 2011-02-03 0:45

Name: Anonymous 2011-02-04 19:27

Name: Anonymous 2011-02-25 11:02

Looks like it doesn't work in opera 11 ATM

Name: Anonymous 2011-02-25 11:37

>>29
opera
lack of sage
Back to /g/, pathetic fool.

Name: Anonymous 2011-02-25 12:27

>>30
can't multiline [o] quote
Back to /b/, please.

Name: Anonymous 2011-02-25 12:40

>>31
the hell you say, son
I was making a point
unlike you
who should fail back to /b/

Name: Anonymous 2011-02-25 13:26

<--- dubs checkem

Name: Anonymous 2011-02-25 14:03

>>31
>thinks there was a multiline quote in that post
>thinks [o] is an acceptable method of multiline quoting
>can't escape bbcode tags
>can't >imply
Just leave the internet.  You'll never understand.

Name: VIPPER 2011-02-25 14:05

Thread reported.

Name: Anonymous 2011-02-25 14:21

>>31-34
That's not how you quote. Both of you, POLECAT KEBABS.

Name: Anonymous 2011-02-25 14:22

>>36
Shit, s/\-/\,/

Name: Anonymous 2011-02-25 14:29

>>36
Good, because I wasn't quoting anything.  Learn to read words before you tell people where to put them.

Name: Anonymous 2011-02-25 14:42

>>34
OKAY YOU FUQIN ANGERED AN EXPERT BBCoder
GODFUQINDAMN
FIRST OF ALL, YOU DON'T FUQIN QUOTE WITH > WITHOUT A SPACE IN /prog/
SECONDLY, [o] MULTILINE QUOTE ARE SUPERIOR TO [br] QUOTE SINCE THEY ALLOW INFINITE NESTING
THIRDLY, THIS IS /prog/, YOU NEVER >imply
AND FUQIN LASTLY, FUCK OFF WITH YOUR IMAGEBOARD BULLSHITE
EVERYTHING HAS ALREADY BEEN ANSWERED IN >>31,35-36

Name: Anonymous 2011-02-25 14:46

>>39
Small-minded whelp, you still don't understand.  I guess there's no helping you.  /prog/ continues its decline.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List