diff --git a/README.md b/README.md new file mode 100644 index 0000000..cfe5db1 --- /dev/null +++ b/README.md @@ -0,0 +1,51 @@ +# localbitcoins filter + +This tampermonkey script is designed to add some filtering to localbitcoins site results. + +It's a small modification but it has helped me. It does 2 things: + +- Sorts results by dollar amounts (click on table header "Price / BTC") +- Hide users that are offline or seen recently + +These 2 mods allowed me to easily view the highest/lowest amounts and see those who were ready to do a trade now. localbitcoins is a nice looking site but I'm surprised they didn't add some basic filtering. + +# Install + +This has only been tested on Chrome but should work on Firefox. To get it working on Chrome you need to install the following extension: + +- [Tampermonkey](https://chrome.google.com/webstore/detail/tampermonkey/dhdgffkkebhmkfjojejmpbldmpobfkfo?hl=en) + +Tampermonkey is an extension which allows people to easily write code that can be ran on a given page. It also has a built in update engine which makes it easy to keep scripts up to date. + +# How to use + +Attempting to download the javascript file should trigger tampermonkey to detect that it is a tamper monkey script and install it. + +Once installed just navigate to localbitcoins.com and view results (or if you have a window open already - you will need to refresh the page for the script to load) + +This will add 2 checkboxes below the navigation bar titled "Hide Recent" and "Hide Offline". Checking either will toggle the display of recent/offline. You may also click on "Price / BTC" to sort the list. + +# FAQs + +Q: How Does this work? +A: It adds some Javascript onto the page and leverages jQuery for some of the scripting. + +Q: Can you steal my account/my BTC in my account? +A: You have my word (check out my background) that I would NEVER introduce any code to steal accounts or BTC. However, there are bad/stupid/greedy people out there who would create a script that would do that. + +Q: Can you add X feature? +A: I can look into it - post a ticket/bug on github or srchub. + +Q: This doesn't work! +A: See above question. + +Q: Can I take this script and modify it/redistribute it? +A: Of course - as long as you follow the license (that's the point of applying a license). + +# Donations + +If you feel this script was useful please feel free to send BTC to this address - 1kqfr9hYPHTwGdMev9b538sSeyLa5h4FR + +# License + +This script is licensed under MIT \ No newline at end of file diff --git a/localbitcoinsfilter.user.js b/localbitcoinsfilter.user.js new file mode 100644 index 0000000..e51b9e4 --- /dev/null +++ b/localbitcoinsfilter.user.js @@ -0,0 +1,142 @@ +// ==UserScript== +// @name localbitcoins filter +// @namespace https://srchub.org +// @version 0.2 +// @description Adds some filters and sorting to localbitcoins +// @author Nathan Adams +// @match https://localbitcoins.com/* +// @grant none +// ==/UserScript== +// License: MIT +// +// If you feel this script was useful please send BTC donations to this address: +// 1kqfr9hYPHTwGdMev9b538sSeyLa5h4FR +// +// Mirrors: +// https://github.com/nadams810/localbitcoinsfilter +// https://srchub.org/p/localbitcoinsfilter/ + +/** + * jQuery.fn.sortElements + * -------------- + * @author James Padolsey (http://james.padolsey.com) + * @version 0.11 + * @updated 18-MAR-2010 + * -------------- + * @param Function comparator: + * Exactly the same behaviour as [1,2,3].sort(comparator) + * + * @param Function getSortable + * A function that should return the element that is + * to be sorted. The comparator will run on the + * current collection, but you may want the actual + * resulting sort to occur on a parent or another + * associated element. + * + * E.g. $('td').sortElements(comparator, function(){ + * return this.parentNode; + * }) + * + * The 's parent () will be sorted instead + * of the itself. + */ +jQuery.fn.sortElements = (function(){ + + var sort = [].sort; + + return function(comparator, getSortable) { + + getSortable = getSortable || function(){return this;}; + + var placements = this.map(function(){ + + var sortElement = getSortable.call(this), + parentNode = sortElement.parentNode, + + // Since the element itself will change position, we have + // to have some way of storing it's original position in + // the DOM. The easiest way is to have a 'flag' node: + nextSibling = parentNode.insertBefore( + document.createTextNode(''), + sortElement.nextSibling + ); + + return function() { + + if (parentNode === this) { + throw new Error( + "You can't sort elements if any one is a descendant of another." + ); + } + + // Insert before flag: + parentNode.insertBefore(this, nextSibling); + // Remove flag: + parentNode.removeChild(nextSibling); + + }; + + }); + + return sort.call(this, comparator).each(function(i){ + placements[i].call(getSortable.call(this)); + }); + + }; + +})(); + + +$(".pagination-block").first().after('Hide Recent | Hide Offline '); + +$("#hideRecent").click(function(e) { + $(".online-status-recent").closest("tr").toggle(); +}); + +$("#hideOffline").click(function(e) { + $(".online-status-offline").closest("tr").toggle(); +}); + +var table = $('.table-bitcoins').first(); + + $('.header-price').first() + .wrapInner('') + .each(function(){ + + var th = $(this), + thIndex = th.index(), + inverse = false; + + th.click(function(){ + + table.find('td').filter(function(){ + + return $(this).index() === thIndex; + + }).sortElements(function(a, b){ + return Number(jQuery.trim($.text([a])).split(" ")[0]) > Number(jQuery.trim($.text([b])).split(" ")[0]) ? + inverse ? -1 : 1 + : inverse ? 1 : -1; + + }, function(){ + + // parentNode is the element we want to move + return this.parentNode; + + }); + + inverse = !inverse; + + }); + + }); + +$(".header-price").first().hover(function() { + $(this).css('cursor','pointer'); +}, function() { + $(this).css('cursor','auto'); +}); +$('.header-price').click(); +if (window.location.href.indexOf("sell") > -1) { + $('.header-price').click(); +} \ No newline at end of file