Bookmarklet now checks if ext is supported/filesize is lower than limit before attempting to upload.

This commit is contained in:
Daku 2012-01-17 07:57:58 +00:00
parent 433197e187
commit a45c09b2b6
2 changed files with 42 additions and 13 deletions

View File

@ -1,16 +1,31 @@
/* Imageboard to Shimmie */ /* Imageboard to Shimmie */
// This should work with "most" sites running Danbooru/Gelbooru/Shimmie // This should work with "most" sites running Danbooru/Gelbooru/Shimmie
var maxsze = (maxsze.match("(?:\.*[0-9])")) * 1024; //This assumes we are only working with MB.
var toobig = "The file you are trying to upload is too big to upload!";
var notsup = "The file you are trying to upload is not supported!";
if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){}else{var tag=prompt("Enter Tags","");var chk=1;}; if (confirm("OK = Use Current tags.\nCancel = Use new tags.")==true){}else{var tag=prompt("Enter Tags","");var chk=1;};
// Danbooru // Danbooru
if(document.getElementById("post_tags") !== null){ if(document.getElementById("post_tags") !== null){
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("post_tags").value;} if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("post_tags").value;}
var rtg=document.documentElement.innerHTML.match("<li>Rating: (.*)<\/li>")[1]; var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+\/"); var srx="http://" + document.location.hostname + document.location.href.match("\/post\/show\/[0-9]+\/");
var filesze=document.getElementById("stats").innerHTML.match("[0-9] \\(((?:\.*[0-9])) ([a-zA-Z]+)");
if(filesze[2] == "MB"){var filesze = filesze[1] * 1024;}else{var filesze = filesze[2].match("[0-9]+");}
if(tag.search(/\bflash\b/)==-1){ if(tag.search(/\bflash\b/)==-1){
location.href=ste+document.getElementById("highres").href+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx; if(supext.search(document.getElementById("highres").href.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
if(filesze <= maxsze){
location.href=ste+document.getElementById("highres").href+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx;
}else{alert(toobig);}
}else{alert(notsup);}
}else{ }else{
location.href=ste+document.getElementsByName("movie")[0].value+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx; if(supext.search(document.getElementById("highres").href.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
if(filesze <= maxsze){
location.href=ste+document.getElementsByName("movie")[0].value+"&tags="+tag+"&rating="+rtg[1]+"&source="+srx;
}else{alert(toobig);}
}else{alert(notsup);}
} }
} }
/* Shimmie /* Shimmie
@ -21,23 +36,31 @@ else if(document.getElementsByTagName("title")[0].innerHTML.search("Image [0-9.-
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementsByTagName("title")[0].innerHTML.match("Image [0-9.-]+\: (.*)")[1];} if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementsByTagName("title")[0].innerHTML.match("Image [0-9.-]+\: (.*)")[1];}
//TODO: Make rating show in statistics. //TODO: Make rating show in statistics.
var srx="http://" + document.location.hostname + document.location.href.match("\/post\/view\/[0-9]+"); var srx="http://" + document.location.hostname + document.location.href.match("\/post\/view\/[0-9]+");
/*TODO: Figure out regex for shortening file link. /*TODO: Figure out regex for shortening file link. I.E http://blah.net/_images/1234abcd/everysingletag.png > http://blah.net/_images/1234abcd.png*/
I.E http://blah.net/_images/1234abcd/everysingletag.png > http://blah.net/_images/1234abcd.png /*TODO: Make file size show on all themes (Only seems to show in lite/Danbooru themes.)*/
.match("WEBSITE.NET\/_images\/[A-Za-z0-9]+", "(\\.[a-z][a-z]+)")*/
if(tag.search(/\bflash\b/)==-1){ if(tag.search(/\bflash\b/)==-1){
location.href=ste+document.getElementById("main_image").src+"&tags="+tag+"&source="+srx; var img = document.getElementById("main_image").src;
if(supext.search(img.match(".*\\.([a-z0-9]+)")[1]) !== -1){
location.href=ste+img+"&tags="+tag+"&source="+srx;
}else{alert(notsup);}
}else{ }else{
location.href=ste+document.location.hostname+document.getElementsByName("movie")[0].value+"&tags="+tag+"&source="+srx; var mov = document.location.hostname+document.getElementsByName("movie")[0].value;
if(supext.search(mov.match(".*\\.([a-z0-9]+)")[1]) !== -1){
location.href=ste+mov+"&tags="+tag+"&source="+srx;
}else{alert(notsup);}
} }
} }
// Gelbooru // Gelbooru
else if(document.getElementById("tags") !== null){ else if(document.getElementById("tags") !== null){
//Gelbooru has an annoying anti-hotlinking thing which doesn't seem to like the bookmarklet... //Gelbooru has an annoying anti-hotlinking thing which doesn't seem to like the bookmarklet.
if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("tags").value;} if (typeof tag !=="ftp://ftp." && chk !==1){var tag=document.getElementById("tags").value;}
var rtg=document.documentElement.innerHTML.match("<li>Rating: (.*)<\/li>")[1]; var rtg=document.getElementById("stats").innerHTML.match("<li>Rating: (.*)<\/li>")[1];
//Can't seem to grab source due to url containing a & //Can't seem to grab source due to url containing a &
//var srx="http://" + document.location.hostname + document.location.href.match("\/index\.php?page=post&amp;s=view\\&amp;id=.*"); //var srx="http://" + document.location.hostname + document.location.href.match("\/index\.php?page=post&amp;s=view\\&amp;id=.*");
var gmi=document.getElementById("image").src.match(".*img[0-9]+\.gelbooru\.com\/\/images\/[0-9]+\/[a-z0-9]+\.[a-z0-9]+")[0]; var gmi=document.getElementById("image").src.match(".*img[0-9]+\.gelbooru\.com\/\/images\/[0-9]+\/[a-z0-9]+\.[a-z0-9]+")[0];
//Since Gelbooru does not allow flash, no need to search for flash tag. //Since Gelbooru does not allow flash, no need to search for flash tag.
location.href=ste+gmi+"&tags="+tag+"&rating="+rtg[1];//+"&source="+srx; //Gelbooru doesn't show file size in statistics either...
if(supext.search(gmi.match("http\:\/\/.*\\.([a-z0-9]+)")[1]) !== -1){
location.href=ste+gmi+"&tags="+tag+"&rating="+rtg[1];//+"&source="+srx;
}else{alert(notsup);}
} }

View File

@ -146,9 +146,15 @@ class UploadTheme extends Themelet {
It would also work with Gelbooru but unless someone can figure out how to bypass their hotlinking..meh. It would also work with Gelbooru but unless someone can figure out how to bypass their hotlinking..meh.
The bookmarklet is now also loaded via the .js file in this folder. The bookmarklet is now also loaded via the .js file in this folder.
*/ */
//Bookmarklet checks if shimmie supports ext. If not, won't upload to site/shows alert saying not supported.
$supported_ext = "jpg jpeg gif png";
if(file_exists("ext/handle_flash")){$supported_ext .= " swf";}
if(file_exists("ext/handle_ico")){$supported_ext .= " ico ani cur";}
if(file_exists("ext/handle_mp3")){$supported_ext .= " mp3";}
if(file_exists("ext/handle_svg")){$supported_ext .= " svg";}
$title = "Booru to " . $config->get_string('title'); $title = "Booru to " . $config->get_string('title');
$html .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(make_link("ext/upload/bookmarklet.js")).'&quot;)">'. $html .= '<p><a href="javascript:var ste=&quot;'. $link . $delimiter .'url=&quot;; var supext=&quot;'.$supported_ext.'&quot;; var maxsze=&quot;'.$max_kb.'&quot;; void(document.body.appendChild(document.createElement(&quot;script&quot;)).src=&quot;'.make_http(make_link("ext/upload/bookmarklet.js")).'&quot;)">'.
$title . '</a> (Click when looking at an image page. Works on sites running Shimmie or Danbooru. (This also grabs the tags/rating/source!))'; $title . '</a> (Click when looking at an image page. Works on sites running Shimmie/Danbooru/Gelbooru. (This also grabs the tags/rating/source!))';
} }
} }