Last active
September 14, 2017 19:39
-
-
Save stpettersens/481487dd5200e3aa69b16a9d80fa5f75 to your computer and use it in GitHub Desktop.
User script to display estimated number of trees planted with Ecosia.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Ecosia Trees Planted | |
// @namespace 481487dd5200e3aa69b16a9d80fa5f75 | |
// @version 0.3 | |
// @description Display estimated number of trees planted with Ecosia. | |
// @author Sam Saint-Pettersen <[email protected]> | |
// @match https://www.ecosia.org/* | |
// @icon https://s2.postimg.org/407qv942h/small-tree-icon-0.jpg | |
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
$(document).ready(function() { | |
let searches = $('.tree-counter-text').text(); // Get number of searches. | |
const trees = Math.floor(parseInt(searches.replace(',', '')) / 45); // Calculate ~ trees planted. | |
// Ecosia says that it takes around 45 searches to plant 1 tree. | |
// Replace searches with estimate of trees planted. | |
let noun = ' tree'; | |
if(trees < 1 || trees > 1) noun += 's'; // 0 trees, 1 tree, 2 trees, etc. | |
$('.tree-counter-text').text('~ ' + trees + noun + ' (' + searches + ')'); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://imgur.com/a/mFDvK