Skip to content

Instantly share code, notes, and snippets.

@stpettersens
Last active September 14, 2017 19:39
Show Gist options
  • Save stpettersens/481487dd5200e3aa69b16a9d80fa5f75 to your computer and use it in GitHub Desktop.
Save stpettersens/481487dd5200e3aa69b16a9d80fa5f75 to your computer and use it in GitHub Desktop.
User script to display estimated number of trees planted with Ecosia.
// ==UserScript==
// @name Ecosia Trees Planted
// @namespace 481487dd5200e3aa69b16a9d80fa5f75
// @version 0.3
// @description Display estimated number of trees planted with Ecosia.
// @author Sam Saint-Pettersen <s.stpettersen+github@gmail.com>
// @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 + ')');
});
})();
@stpettersens
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment