Skip to content

Instantly share code, notes, and snippets.

@jricardo27
Last active August 29, 2015 14:18
Show Gist options
  • Save jricardo27/739ca754ddfc956a4743 to your computer and use it in GitHub Desktop.
Save jricardo27/739ca754ddfc956a4743 to your computer and use it in GitHub Desktop.
Display plain text with the basic information ready to copy to Google Maps
// ==UserScript==
// @name Lonely Planet Easy Copy LP-EC
// @namespace jricardo27
// @include http://www.lonelyplanet.com/*
// @version 0.0.3
// @require https://code.jquery.com/ui/1.10.4/jquery-ui.min.js
// @grant GM_info
// ==/UserScript==
function GM_main ($) {
var newline = '\r\n\r\n';
console.log("Lonely Planet EC: jQuery is installed with no conflicts! "
+ "The version is: " + $.fn.jquery);
function getSiteName() {
return $('.card--page__header--headline h1').text().trim();
}
function getDescription() {
return $('.ttd__section--description').text().trim();
}
function getInfoListItem(index) {
return $($('.info-list dd')[index]).text().trim();
}
function getPrice() {
return "Prices" + newline + getInfoListItem(2);
}
function getOpening() {
return "Opening hours" + newline + getInfoListItem(3);
}
function getImageUrl() {
return $($('.media-gallery__img')[0]).prop('src');
}
function showInfo() {
var info = getImageUrl() + newline;
info += getSiteName() + newline;
info += getPrice() + newline + "\n";
info += getOpening() + newline + "\n";
info += getDescription();
var mytextarea = $('<textarea id="LPEC" '
+ 'style="width: 900px; height: 300px">'
+ info
+ '</textarea>');
// Insert textarea at the top
$('body').prepend(mytextarea);
}
$(document).ready(function() {
showInfo();
});
}
if (typeof jQuery === "function") {
console.log("Lonely Planet EC: Running with local copy of jQuery!");
GM_main(jQuery);
}
else {
console.log("Lonely Planet EC: fetching jQuery from some "
+ "3rd-party server.");
add_jQuery(GM_main);
}
function add_jQuery (callbackFn) {
var D = document;
var targ = D.getElementsByTagName ('head')[0] || D.body ||
D.documentElement;
var scriptNode = D.createElement ('script');
scriptNode.src = 'https://code.jquery.com/ui/1.10.4/jquery-ui.min.js';
scriptNode.addEventListener ("load", function () {
var scriptNode = D.createElement ("script");
scriptNode.textContent =
'var gm_jQuery = jQuery.noConflict (true);\n'
+ '(' + callbackFn.toString () + ')(gm_jQuery);'
;
targ.appendChild (scriptNode);
}, false);
targ.appendChild (scriptNode);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment