Skip to content

Instantly share code, notes, and snippets.

@peterhost
Created November 27, 2011 12:59
Show Gist options
  • Select an option

  • Save peterhost/1397528 to your computer and use it in GitHub Desktop.

Select an option

Save peterhost/1397528 to your computer and use it in GitHub Desktop.
Quick and Dirty Bookmarklet for the excellent https://github.com/KrofDrakula/microdata-tool
// modified from code of "JQuerify" bookmarklet
// http://www.learningjquery.com/2009/04/better-stronger-safer-jquerify-bookmarklet
(function() {
function z(a, b) {
var c = document.createElement("script");
c.src = a;
var d = document.getElementsByTagName("head")[0], e = !1;
c.onload = c.onreadystatechange = function() {
!e && (!this.readyState || this.readyState === "loaded" || this.readyState === "complete") && (e = !0, b(), c.onload = c.onreadystatechange = null, d.removeChild(c));
};
d.appendChild(c);
}
function d() {
a.innerHTML = msg, b.appendChild(a), window.setTimeout(function() {
typeof jQuery == "undefined" ? b.removeChild(a) : (jQuery(a).fadeOut("slow", function() {
jQuery(this).remove();
}), otherlib && ($jq = jQuery.noConflict()));
}, 2500);
}
var a = document.createElement("div"), b = document.getElementsByTagName("body")[0];
otherlib = !1, msg = "", a.style.position = "fixed", a.style.height = "32px", a.style.width = "220px", a.style.marginLeft = "-110px", a.style.top = "0", a.style.left = "50%", a.style.padding = "5px 10px", a.style.zIndex = 1001, a.style.fontSize = "12px", a.style.color = "#222", a.style.backgroundColor = "#f99";
//load jquery (if not already loaded)
if (typeof jQuery != "undefined") {
msg = "This page already using jQuery v" + jQuery.fn.jquery + "... proceeding", d();
} else {
typeof $ == "function" && (otherlib = !0), z("http://code.jquery.com/jquery-latest.min.js", function() {
return typeof jQuery == "undefined" ? msg = "Sorry, but jQuery wasn't able to load" : (msg = "This page is now jQuerified with v" + jQuery.fn.jquery, otherlib && (msg += " and noConflict(). Use $jq(), not $().")), d();
});
}
//load jquery.microdata.js
typeof $ == "function" && (otherlib = !0), z("https://github.com/KrofDrakula/microdata-tool/raw/master/jquery.microdata.js", function() {
return typeof $.microdata == "undefined" ? msg = "Sorry, but jquery.microdata.js wasn't able to load" : (msg = "jquery.microdata.js loaded " );
});
//load schema.js
typeof $ == "function" && (otherlib = !0), z("https://github.com/KrofDrakula/microdata-tool/raw/master/schemas.js", function() {
// didn't find what to test schema.js against
return typeof $.microdata == "undefined" ? msg = "Sorry, but schema.js wasn't able to load" : (msg = "schema.js loaded " );
});
})();
javascript: (function(){function a(a,b){var c=document.createElement("script");c.src=a;var d=document.getElementsByTagName("head")[0],e=!1;c.onload=c.onreadystatechange=function(){!e&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")&&(e=!0,b(),c.onload=c.onreadystatechange=null,d.removeChild(c))},d.appendChild(c)}function b(){c.innerHTML=msg,d.appendChild(c),window.setTimeout(function(){typeof jQuery=="undefined"?d.removeChild(c):(jQuery(c).fadeOut("slow",function(){jQuery(this).remove()}),otherlib&&($jq=jQuery.noConflict()))},2500)}var c=document.createElement("div"),d=document.getElementsByTagName("body")[0];otherlib=!1,msg="",c.style.position="fixed",c.style.height="32px",c.style.width="220px",c.style.marginLeft="-110px",c.style.top="0",c.style.left="50%",c.style.padding="5px 10px",c.style.zIndex=1001,c.style.fontSize="12px",c.style.color="#222",c.style.backgroundColor="#f99",typeof jQuery!="undefined"?(msg="This page already using jQuery v"+jQuery.fn.jquery+"... proceeding",b()):(typeof $=="function"&&(otherlib=!0),a("http://code.jquery.com/jquery-latest.min.js",function(){return typeof jQuery=="undefined"?msg="Sorry, but jQuery wasn't able to load":(msg="This page is now jQuerified with v"+jQuery.fn.jquery,otherlib&&(msg+=" and noConflict(). Use $jq(), not $().")),b()})),typeof $=="function"&&(otherlib=!0),a("https://github.com/KrofDrakula/microdata-tool/raw/master/jquery.microdata.js",function(){return typeof $.microdata=="undefined"?msg="Sorry, but jquery.microdata.js wasn't able to load":msg="jquery.microdata.js loaded "}),typeof $=="function"&&(otherlib=!0),a("https://github.com/KrofDrakula/microdata-tool/raw/master/schemas.js",function(){return typeof $.microdata=="undefined"?msg="Sorry, but schema.js wasn't able to load":msg="schema.js loaded "})})();
@e-orlov

e-orlov commented Mar 10, 2014

Copy link
Copy Markdown

Hi! on some sites there is only alert about JQuery is loaded, but no microdata widget, and on another sites even no JQuery loaded alert - just nothing...:( on some https sites after clicking onto bookmarklet i get an alert, FF blocked unsecure content. Have you ever seen such misbehavior?

@GraniteConsultingReviews

Copy link
Copy Markdown

I try this code but this is not working

@Lucas-C

Lucas-C commented Jul 16, 2020

Copy link
Copy Markdown

This currently does not work on Firefox due to incorrect MIME types (text/plain) of the URLs served by github.com/KrofDrakula/microdata-tool/raw/...:

La ressource à l’adresse « https://raw.githubusercontent.com/KrofDrakula/microdata-tool/master/jquery.microdata.js » a été bloquée en raison d’un type MIME (« text/plain ») incorrect (X-Content-Type-Options: nosniff).
Échec du chargement pour l’élément <script> dont la source est « https://github.com/KrofDrakula/microdata-tool/raw/master/jquery.microdata.js ». blog:1:1
La ressource à l’adresse « https://raw.githubusercontent.com/KrofDrakula/microdata-tool/master/schemas.js » a été bloquée en raison d’un type MIME (« text/plain ») incorrect (X-Content-Type-Options: nosniff).
Échec du chargement pour l’élément <script> dont la source est « https://github.com/KrofDrakula/microdata-tool/raw/master/schemas.js ».

(errors are in French)

Using those URLs instead fixed the issue:

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