Skip to content

Bookmarklets

alex [dot] kramer [at] g_m_a_i_l [dot] com edited this page Nov 27, 2019 · 7 revisions

Generate bookmarklets from javascript using http://mrcoles.com/bookmarklet/.

Content expander

Increase content width on sites that often display code that is longer than the content width.

Bookmarklet:

(function()%7Bvar%20host%20%3D%20location.hostname%3Bif%20(host.includes('github.com'))%20%7Bdocument.querySelectorAll('.repository-content')%5B0%5D.style.width%20%3D%20%221375px%22%3Bdocument.querySelectorAll('.discussion-timeline')%5B0%5D.style.width%20%3D%20%221150px%22%3Bvar%20containers%20%3D%20document.querySelectorAll('.container')%3Bcontainers.forEach(function(e)%20%7Be.style.marginLeft%20%3D%20%2220px%22%3B%7D)%3B%7Dif%20(host.includes('stackoverflow.com')%20%7C%7C%20host.includes('stackexchange.com'))%20%7Bdocument.querySelectorAll('%23content')%5B0%5D.style.width%20%3D%20%221450px%22%3Bvar%20posts%20%3D%20document.querySelectorAll('.post-text')%3Bposts.forEach(function(e)%20%7Be.style.width%20%3D%20%221150px%22%3B%7D)%3B%7D%7D)()
// javascript:(function()%7Bvar host %3D location.hostname%3Bif (host.includes('github.com')) %7Bdocument.querySelectorAll('.repository-content')%5B0%5D.style.width %3D "1375px"%3Bdocument.querySelectorAll('.discussion-timeline')%5B0%5D.style.width %3D "1150px"%3Bvar containers %3D document.querySelectorAll('.container')%3Bcontainers.forEach(function(e) %7Be.style.marginLeft %3D "20px"%3B%7D)%3B%7Dif (host.includes('stackoverflow.com') %7C%7C host.includes('stackexchange.com')) %7Bdocument.querySelectorAll('%23content')%5B0%5D.style.width %3D "1450px"%3Bvar posts %3D document.querySelectorAll('.post-text')%3Bposts.forEach(function(e) %7Be.style.width %3D "1150px"%3B%7D)%3B%7D%7D)()

Source:

var host = location.hostname;

if (host.includes('github.com')) {
  document.querySelectorAll('.repository-content')[0].style.width = "1375px";
  document.querySelectorAll('.discussion-timeline')[0].style.width = "1150px";
  
  var containers = document.querySelectorAll('.container');
  containers.forEach(function(e) {e.style.marginLeft = "20px";});
}

if (host.includes('stackoverflow.com') || host.includes('stackexchange.com')) {
  document.querySelectorAll('#content')[0].style.width = "1450px";

  var posts = document.querySelectorAll('.post-text');
  posts.forEach(function(e) {e.style.width = "1150px";});
}

/* JQuery no longer loads on github
var host = location.hostname;
if (host.includes('github.com')) {
  $('.repository-content').width(1100);
}
if (host.includes('stackoverflow.com') || host.includes('stackexchange.com')) {
  $('#content').width(1450);
  $('.post-text').each(function(e) {$(this).width(1150)});
}
*/

TDAmeritrade transaction search PnL calculator

Bookmarklet:

javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3Balert(%22PnL%3A%20%22%20%2B%20%24(%22.posChange%2C%20.negChange%22).map(%20function()%20%7B%20return%20this.innerText%3B%20%7D%20).toArray().reduce(function(tot%2C%20num)%20%7B%20return%20parseFloat(tot)%20%2B%20parseFloat(num)%3B%20%7D))%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.11.1%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()

Source:

alert("PnL: " + $(".posChange, .negChange").map( function() { return this.innerText; } ).toArray().reduce(function(tot, num) { return parseFloat(tot) + parseFloat(num); }))
Clone this wiki locally