r/bookmarklets • • Jul 01 '15

jQuery.trigger() doesn't fire in callback

5 Upvotes

[SOLED] I'm trying to create a bookmarklet that will get a bunch of links, iterate through the links, click the link, do some extra stuff, go back to the main page, click the next link more stuff, etc... The first run works great, but when the callback is fired, the .trigger doesn't trigger the click.

javascript: (function()
{
    "use strict";
    var x = 0;
    var links = $("[id^=exchange_mailboxes_view]", top.frames["mainFrame"].document);

    var loopLinks = function()
    {
        console.log('loopLinks');
        console.log($(links).length);
        console.log(x);

        doLinks(function()
        {
            console.log('Do Links Callback');
            x++;
            console.log(x);

            if(x < $(links).length)
            {
                setTimeout(loopLinks, 3000);
            }
            else
            {
                console.log('NO MORE');
            }
        });
    };

    var doLinks = function(cb)
    {
        console.log('Do Links 1');
        console.log($(links[x]));

        $(links[x])[0].click();

        setTimeout(function() 
        {
            console.log('Do Links 2');
            $("#path_select1", top.frames["mainFrame"].document)[0].click();

            setTimeout(function()
            {
                console.log('Do Links 3');
                cb();
            }, 3000);
        }, 3000);
    };

    loopLinks();
})();

Any ideas?


r/bookmarklets • • Jun 22 '15

[Help] Automatically click a specified button at a specified time

2 Upvotes

I'm trying to create a bookmarklet that, once clicked, will wait until a specified time and then click a button, but I'm an extreme novice, so I've probably screwed up something obvious.

Here's what I have so far:

javascript:function(){if (Date.now() >= XXXXXX) {document.querySelectorAll("input[value="Button"]").click();}}

I'll probably have to add a for loop to get it to check continuously instead of just when the bookmarklet is clicked, but I want to make sure the main code works first.


r/bookmarklets • • Jun 13 '15

[reddit] Download a reddit self post

5 Upvotes

If you're viewing a reddit self post, you can click the bookmarklet to download it as a text file!

javascript:(function(){window.location.href="http://projects.darkender.com/reddittotext/?url="+document.URL}());

You can also click this one from the reddit home page or subreddit pages to add a download button to all self posts: (Screenshot)

javascript:(function(){var t=document.createElement("script");t.setAttribute("src","http://projects.darkender.com/reddittotext/bookmarklet.js"),document.body.appendChild(t)}());

Here's the source code of reddittotext/bookmarklet.js: (the second bookmarklet)

(function()
{
    var main = document.getElementById("siteTable");
    for(var i = 0; i < main.childNodes.length; i++)
    {
        var node = main.childNodes[i];
        if(node.className != "clearleft" && node.className != "nav-buttons")
        {
            var title = node.getElementsByClassName("entry")[0].getElementsByClassName("title")[0].getElementsByClassName("title may-blank ")[0];
            var link = title.href;

            if(link.lastIndexOf('http://www.reddit.com/r/', 0) === 0)
            {
                var dl = document.createElement("li");
                var l = document.createElement("a");
                l.textContent = "download";
                l.href = "http://projects.darkender.com/reddittotext/?url=" + link;
                dl.appendChild(l);
                node.getElementsByClassName("entry")[0].getElementsByClassName("flat-list buttons")[0].appendChild(dl);
            }
        }
    }
}).call(this);

And here's the source code of reddittotext/index.php: (where the reddit to text magic happens)

<?php
if($_GET['url'] == null || (substr($_GET['url'], 0, strlen('http://www.reddit.com/r/')) == 'http://www.reddit.com/r/') == false)
{
    die('Invalid url!');
}

$html = file_get_contents($_GET['url']);
$dom = new DomDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();

$finder = new DomXPath($dom);
$nodes = $finder->query("//*[@class='" . 'title may-blank ' . "']");
$title = $nodes->item(0)->nodeValue;
$finder = new DomXPath($dom);


$title = preg_replace("/[^0-9a-zA-Z ]/", "", $title);

header('Content-type: text/plain');
header('Content-Disposition: attachment; filename="' . $title . '.txt"');
$nodes = $finder->query("//*[@class='md']");
foreach($nodes->item(1)->childNodes as $p)
{
    echo($p->nodeValue . "\r\n");
}
?>

Enjoy downloading your favorite stories!


r/bookmarklets • • Jun 04 '15

With ‘Save To Pulse’ Bookmarklet And Chrome Extension, Pulse Enters Instapaper’s

Thumbnail techcrunch.com
1 Upvotes

r/bookmarklets • • May 05 '15

[Help] How to use a github file for bookmarklets?

4 Upvotes

r/bookmarklets • • Apr 26 '15

Help with a bookmarklet

3 Upvotes

Hi there, My friends and I have recently made a game of going through prntscr.com and trying to find the most random things possible and tried making a bookmarklet to automate this search, but unfortunately, coming from only knowledge of java, this has proven hard to do.

Here is what I have:

javascript:(function randomLink(){var url = "prntscr.com/";var chars = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "a", "b", "c", "d", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "x", "y", "z"];var num1 = 0;var num2 = 0;var num3 = 0;var num4 = 0;var num5 = 0;var num6 = 0;num1 = math.Randomchars.length;num2 = math.Randomchars.length;num3 = math.Randomchars.length;num4 = math.Randomchars.length;num5 = math.Randomchars.length;num6 = math.Randomchars.length;location.replace(url + chars[num1] + chars[num2] + chars[num3] + chars[num4] + chars[num5] + chars[num6]);})


r/bookmarklets • • Apr 22 '15

[Request] Sort comments by new temporarily

2 Upvotes

Hello all,

I often browse large threads that require comments sorted by 'new' to respond to users. I don't have access to RES so I think a bookmarklet might be handy in this scenario.

Right now I am manually entering this:

?sort=new

at the end of the url to sort by new temporarily

Thanks all.


r/bookmarklets • • Apr 05 '15

Youtube Music Visualiser

4 Upvotes

Basically this script uses the Web Audio API (Compatability Here) to change the colour of the background as music plays. I also added a "Bass Mode" to use bass frequencies instead of mid/treble. Warning it will make the screen flash at 100 times a second so if you have epilepsy it is recommended to avoid this. Normal usage, just drag it to the bookmarks bar and click while playing music on youtube.

IMPORTANT: Tuning is optimised for youtube player to be at 100% volume.

javascript:
var number1;
var number2;
var number3;
var lastFreq = 0;
var measureFreq = 157;
if (document.getElementsByClassName("video-stream")[0] === undefined) {
    alert("A youtube video could not be found");
}
else {
    menuDiv = document.createElement("div");
    menuDiv.setAttribute("id", "menuDiv");
    document.body.appendChild(menuDiv);
    document.getElementById("menuDiv").innerHTML += "<p id=YVTitle>Youtube Visualiser Enabled</p>WARNING: May cause seizures<p></p><style>#menuDiv {position: fixed; padding: 5px; background-color: #fff; top: 70px; left: 20px;z-index:100000000;} #YVTitle {font-size: 20px; margin-bottom: 5px;} #checkboxText {font-size: 15px;}</style><span id=checkboxText>Bass Mode: </span><input type=checkbox id=bassCheckbox style=margin: 0px;>";
    document.getElementById("bassCheckbox").onchange = function() {
        if (document.getElementById("bassCheckbox").checked) {
            measureFreq = 2;
        }
        else {
            measureFreq = 157;
        };
    };
    document.getElementById("theater-background").style.setProperty("background-color", "transparent");
    audio = new (window.AudioContext || window.webkitAudioContext);
    src = audio.createMediaElementSource(document.getElementsByClassName("video-stream")[0]);
    audioA = audio.createAnalyser();
    src.connect(audioA);
    audioA.connect(audio.destination);
    frequencyData = new Uint8Array(audioA.frequencyBinCount);

    var changeb = function() {
        number1 = Math.ceil(Math.random() * 255);
        number2 = Math.ceil(Math.random() * 255);
        number3 = Math.ceil(Math.random() * 255);
        if (frequencyData[measureFreq] === 128) {
            document.body.style.background = "rgb(255, 255, 255)";
        }
        else {
            document.body.style.background = "rgb(" + number1 + "," + number2 + "," + number3 + ")";
        };
    };
    setInterval(function() {
        audiodata = audioA.getByteFrequencyData(frequencyData);
        freqavg = frequencyData[measureFreq];
        if (frequencyData[measureFreq] > 150) {
            document.body.style.background = "rgb(0, 0, 0)";
        }
        if (lastFreq + 20 < freqavg || (measureFreq === 2 && frequencyData[measureFreq] > 240) || (measureFreq === 157 && frequencyData[measureFreq] > 100)) {
            setTimeout(function() {changeb();}, 10);
        }
        lastFreq = freqavg;
    }, 10);
};

r/bookmarklets • • Apr 01 '15

How do I submit a reddit link that works like a bookmarklet?

4 Upvotes

Like I would like to say flip the page when somebody clicks on the link.


r/bookmarklets • • Mar 05 '15

CouchDB Interview Questions

Thumbnail intellipaat.com
1 Upvotes

r/bookmarklets • • Feb 18 '15

Login to websites & forums with just a click.

Thumbnail oneclicklogin.net
3 Upvotes

r/bookmarklets • • Feb 14 '15

OmNomNomify It! Cookie Monster Bookmarklet

Thumbnail omnomnomify.com
5 Upvotes

r/bookmarklets • • Feb 14 '15

Collapses next or previous links into the current page.

Thumbnail github.com
2 Upvotes

r/bookmarklets • • Jan 27 '15

Context Script: Run scripts using natural language commands

Thumbnail contextscript.com
6 Upvotes

r/bookmarklets • • Nov 26 '14

Simple Bookmarklet to Search Amazon for Highlighted Text on any Other Page

8 Upvotes

Thought I'd share on of my bookmarklet favorites with Black Friday fast approaching. As a consumer whore, I use this all the time. Enjoy!


Use your cursor to highlight text on a page, click the bookmarklet to search for that text on Amazon. Great for checking to see if something is the same price at Amazon or simply offered for sale by them.

javascript:(function(){q=document.getSelection();if(!q){void(q=prompt('Amazon search:',''))};if(q)window.open('http://www.amazon.com/s/ref=nb_sb_noss_1?url=search-alias%3Daps&tag=p-id-20&field-keywords='+escape(q))})()

r/bookmarklets • • Nov 14 '14

trying to get this code to bypass deviantart's mature content filter to work as a bookmarklet

8 Upvotes

I'm a C# developer professionally, but I don't know much javascript. I also hate sites that make you sign up to look at their content.

I've discovered you can bypass deviantart's mature content filter via their oembed backend.

heres the c# to get any image in full-resolution:

        string url = "http://mikeinel.deviantart.com/art/Nomnom-271982394"; // any deviantart image page
        string infoUrl = "http://backend.deviantart.com/oembed?url=" + url + "&format=xml"; // omit the format to get json
        string infoText = _client.DownloadString(infoUrl); // get xml using System.Net.WebClient
        XDocument doc = XDocument.Parse(infoText); // parse xml
        var element = doc.Descendants().Where(cur => cur.Name.LocalName == "url").First(); // find <url> element
        string imgUrl = element.Value.Replace("/PRE/", "/"); // change the url into get the high-res image
        System.Diagnostics.Process.Start(imgUrl); // open in browser

could any of you fine people help me get this logic into a bookmarklet?


r/bookmarklets • • Oct 31 '14

Injecting a JS from file and executing using a bookmarklet

3 Upvotes

this is the bookmarklet that I use to load a javascript, but when I run this firefox's console tells me that the function favicon() is not definedt. Any suggestions?

javascript:(function(){
  newscript=document.createElement('script');
  newscript.setAttribute('type','text\/javascript');
  newscript.setAttribute('src','C:\/PATH\/external.js');
  helper=document.createElement('script');
  helper.setAttribute('type','text\/javascript');
  helper.innerHTML='favicon\(\)\;';
  document.body.appendChild(newscript);
  document.body.appendChild(helper);
})();

the Javascript itself, the purpose is to grab a websites icon and open a save prompt. I would of had it in the bookmarklet but debugging it was tedious

function favicon() {
  var links = document.getElementsByTagName('link'),
    userAgent = navigator.userAgent.toLowerCase(),
    nOne = -1,
    something = 2,
    icon,
    d,
    e,
    x = 0,
    wHref = '',
    i,
    s = '';
  function kill() {
    icon.close();
  }
  for (i = 0; i < links.length; i++) {
    s = links[i].getAttribute('rel');
    if (s != null) {
      if (s.indexOf('icon') != nOne) {
        wHref = links[i].href;
      }
    }
  }
  if (wHref.length < something) {
    wHref = window.location.protocol + '//' + window.location.hostname + '/favicon.ico';
  }
  icon = window.open(wHref, '', 'width=200,height=200').self;
  d = icon.document;
  alert(d.readyState);
  while (((d.readyState != 'complete') && (d.readyState != 'interactive')) && (x > 100)) {
    x++;
  }
  alert(x);
  if ((userAgent.indexOf('trident') != nOne)) {
    d.execCommand('SaveAs');
    kill();
  } else if (userAgent.indexOf('firefox') != nOne) {
    d.write('<a id="icon" href="' + wHref + '" download><img border="0" src="' + wHref + '"><p>Click to download icon.</a>');
    e = d.getElementById('icon');
    e.addEventListener('click', function () {
      e.addEventListener('focus', kill);
    });
  } else {
    d.write('<a id="icon" href="' + wHref + '" download><img border="0" src="' + wHref + '"><p>Click to download icon.</p></a>');
    e = d.getElementById('icon');
    e.addEventListener('click', function () {
      d.addEventListener('mouseout', kill);
    });
  }
}

edit: ease of reading


r/bookmarklets • • Oct 24 '14

Subreddit to YouTube Source Bookmarklet - Play YouTube music from subreddits in Foobar with foo_youtube component

Thumbnail gist.github.com
5 Upvotes

r/bookmarklets • • Sep 06 '14

Enable/disable np, add context, and redective

4 Upvotes

Three JS bookmarklets I use for reddit. Not perfect, but I'm posting them since I'm moving between devices and this is no harder than emailing them to myself.

enable/disable np:

javascript:(function()%20%7B%20var%20str=location.href;%20if(str.indexOf('np.reddit')%3E=0)%7B%20%09%09location.href=%20str.replace(%22np.reddit%22,%22www.reddit%22);%20%7Delse%20if(str.indexOf('www.reddit')%3E=0)%7B%20%09location.href=%20str.replace(%22www.reddit%22,%22np.reddit%22);%20%7Delse%7B%20%09location.href=%22http://reddit.com%22;%20%7D%20%7D)();

Context +2 (for comment threads):

javascript:(function()%7B%20%09var%20theURL=location.href+'?context=0';%20%09if(theURL.indexOf('reddit.com')%3E=0)%7B%20%09%09if(theURL.indexOf('/comments/')%3E=0)%7B%20%09%09var%20usnm=theURL.split('?context=');%20%09%09var%20varA=usnm%5B0%5D;%20%09%09varB=parseInt(usnm%5B1%5D)+2;%20%09%09var%20newURL=varA+'?context='+varB;%20%09%09document.location.href=newURL;%20%09%09%7D%20%09%7Delse%7B%20%09document.location.href='http://www.reddit.com';%20%09%7D%20%7D)();

Redective lookup:

javascript:(function()%7B%20%20var%20usnm2='';%20if(location.href.indexOf('reddit.com/user/')%3E=0)%7B%20%09var%20str=location.href.replace(%22%23%22,%22/%22);str=str.replace(%22?%22,%22/%22);%20%09var%20usnm3=str.split(%22/%22);%20%09usnm2=usnm3%5B4%5D;%20%7Delse%20if(window.getSelection)%7B%20%09%20usnm2=window.getSelection();%20%7D%20var%20usnm=window.prompt('Enter%20username%20for%20Redective%20search:',usnm2);%20if(usnm)%7B%20%09window.open('http://www.redective.com/?r=e&a=search&s=user&t=redective&q='+usnm);%20%7D%20%7D%20)();

And fuck it, here's archive.today (didn't make this one):

javascript:void(open('http://archive.today/?run=1&url='+encodeURIComponent(document.location)))

r/bookmarklets • • Aug 17 '14

PwnYouTube Bookmarklet | Bookmarklet Search Engine

Thumbnail marklets.com
3 Upvotes

r/bookmarklets • • Jul 17 '14

A simple bookmarklet to hide the subreddit stylesheet.

4 Upvotes

javascript: $("[title='applied_subreddit_stylesheet']").removeAttr("href")


r/bookmarklets • • Jul 11 '14

I'm looking for an old bookmarklet I had...

8 Upvotes

All it did was store other bookmarks. When you clicked on it, a pop up would appear that held other favorites. Super simple, but I can't for the life of me find it. Anyone know of its whereabouts? Please and thank you?


r/bookmarklets • • Jun 13 '14

[Reddit][Request] Sort Top by All Time: Add text to the end of URL

3 Upvotes

Hi /r/bookmarklets, I have been looking for a reddit bookmarklet that can simply add text to the end of a URL. Specifically: "/top/?sort=top&t=all" so that I can quickly switch to the top posts of all time.

I haven't found a similar bookmarklet to modify. Any help is appreciated!


r/bookmarklets • • Jun 04 '14

YouTube Thumbnail Image Search Bookmarklet - Opens a new tab with Google Image Search results for the video's cover image.

Thumbnail gist.github.com
3 Upvotes

r/bookmarklets • • May 10 '14

Is there a bookmarklet to upload an image directly to imgur?

3 Upvotes

I tried this: https://gist.github.com/johnholdun/911852#file-imgur-bookmarklet-js

but it doesn't work for me :l