Skip to content

Instantly share code, notes, and snippets.

@mie00
Created July 12, 2016 13:55
Show Gist options
  • Save mie00/fee52b252c26b8c9f6602abc6f35af0a to your computer and use it in GitHub Desktop.
Save mie00/fee52b252c26b8c9f6602abc6f35af0a to your computer and use it in GitHub Desktop.
A script to random restaurants and oreders from otlob.com (add it to grease monkey)
// ==UserScript==
// @name random_order
// @namespace otlob
// @description randomise order
// @include https://www.otlob.com/*
// @version 1
// @grant none
// @authors Mohamed Elawadi <mohamed@elawadi.net>, Ahmed Thabet <xmonader@gmail.com>
// ==/UserScript==
Element.prototype.documentOffsetTop = function () {
return this.offsetTop + (this.offsetParent ? this.offsetParent.documentOffsetTop() : 0);
};
window.randomize = function () {
item_selector = document.URL == 'https://www.otlob.com/restaurants'?'.vendor':'.menu-item';
items = $(item_selector);
items.map(function (index, item) {
item.style.border = '';
})
index = Math.floor(Math.random() * (items.length));
item = items[index];
var top = item.documentOffsetTop() - (window.innerHeight / 2);
window.scrollTo(0, top);
item.style.border = '2px solid cyan';
}
document.body.innerHTML += '<div style="z-index:1200;position:fixed;top:0; right:0;" onclick="randomize()"><i class="icon icon-add"></i></div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment