Skip to content

Instantly share code, notes, and snippets.

@ClemensSahs
Created October 12, 2012 11:09
Show Gist options
  • Save ClemensSahs/3878720 to your computer and use it in GitHub Desktop.
Save ClemensSahs/3878720 to your computer and use it in GitHub Desktop.
check mime type in IANA MIME - DB
/**
* use firebug or a other browser console to exec this script
*
* to create a MimeList set the var(createOnlyMimeList) TRUE
*
* require:
* - jquery
* - browser console ( firebug / chrome )
*
* url: http://www.iana.org/assignments/media-types/index.html
*
*
*/
var createOnlyMimeList = true; // default false; expected true|false
var useConsolePrint = null; // default null; expected null|true|false
var failed = [];
var okCount = 0;
mimeTypeTable = jQuery("html body table tbody tr td table tbody");
mimeRegexp = /^[a-z_-]+\/[a-z0-9\.+_-]+$/i;
mimeTypeMain = jQuery.trim(jQuery("tr:eq(0) td:eq(0)",mimeTypeTable).text());
mimeTypeList = jQuery("tr:not(:eq(0))",mimeTypeTable);
var sum = 0;
useConsolePrint= useConsolePrint === null ? (typeof(console) !== "undefined") : useConsolePrint;
mimeTypeList.each(function(i,dom) {
if ( jQuery(dom).children().length === 0 ) {
return;
};
sum++;
var buffer = jQuery("td:eq(1)", dom).text().split(" ")[0];
buffer = jQuery.trim(buffer);
var mimeType= mimeTypeMain + "/" +
buffer;
if ( createOnlyMimeList ) {
failed.push(mimeType);
return;
}
if ( mimeRegexp.exec(mimeType) ) {
okCount++;
}
else {
if ( useConsolePrint ) {
failed.push( [mimeType,buffer, dom] );
}
failed.push(mimeType + "(" + buffer + ")");
}
});
if ( useConsolePrint ) {
console.log( "sum: " + sum );
console.log( "ok: " + okCount );
console.log( "failed: " , failed );
} else {
alert(
"sum: " + sum + "\n" +
"ok: " + okCount + "\n" +
"failed: \n" +
failed.join("\n")
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment