Skip to content

Commit

Permalink
Fix #4 and another thing
Browse files Browse the repository at this point in the history
Fixed incorrect behavior on tags consisting of reserved words like
"constructor" and fix regression that failed to apply submit changes
when there were autofill options used
  • Loading branch information
Seedmanc committed Sep 29, 2015
1 parent 65b8cb6 commit 89a94fb
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
Binary file not shown.
18 changes: 10 additions & 8 deletions !Firefox addon/contents/data/animage-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ==UserScript==
// @name Animage-get
// @description Format file name & save path for current image by its tags
// @version 1.3
// @version 1.3.1
// @author Seedmanc
// @namespace https://github.com/Seedmanc/Tumblr-image-sorter

Expand Down Expand Up @@ -103,7 +103,7 @@ self.port.on ('init', function(obj){

function main(record){ //Launch tag processing and handle afterwork
if (document.location.href.indexOf('tumblr')==-1) //If not on tumblr
if (!(/(jpe*g|bmp|png|gif)/gi).test(document.location.href.split('.').pop()))
if (!(/(jpe?g|bmp|png|gif)/gi).test(document.location.href.split('.').pop()))
return; // check if this is actually an image link

DBrec=record;
Expand Down Expand Up @@ -169,11 +169,11 @@ function analyzeTags( ) { //This is where the tag matching magic o
});
//1st sorting stage, no prior knowledge about found categories
$.each(tags, function(i,v){ //Divide tags for the image into 5 categories
if (folders[v]) // the "has folder" category
if (folders.hasOwnProperty(v)) // the "has folder" category
fldrs.push(folders[v])
else if (names[v]) // the "no folder name tag" category
else if (names.hasOwnProperty(v)) // the "no folder name tag" category
nms.push(names[v])
else if (meta[v]) // the "no folder meta tag" category,
else if (meta.hasOwnProperty(v)) // the "no folder meta tag" category,
mt.push(meta[v]) // which doesn't count towards final folder decision, but simply adds to filename;
else if (isANSI(v)) {
if (tags.length==1) //If the tag is already in roman and has no folder it might be either name or meta
Expand All @@ -182,11 +182,11 @@ function analyzeTags( ) { //This is where the tag matching magic o
var splt=v.split(' ');
if (splt.length==2) { //Some bloggers put tags for both name reading orders (name<->surname),
var rvrs=splt.reverse().join(' ');
if (names[rvrs]) { // thus creating duplicating tags
if (names.hasOwnProperty(rvrs)) { // thus creating duplicating tags
nms.push(names[rvrs]) // try to find database entry for reversed order first,
return true;
}
else if (ansi[rvrs]) // then check for duplicates
else if (ansi.hasOwnProperty(rvrs)) // then check for duplicates
return true;
}
ansi[v]=true;
Expand Down Expand Up @@ -364,7 +364,7 @@ function selected(e){ //Hide the corresponding roman tag from resul
}
);
$.each(ansi,function(ix,vl){
if ((!unc[vl.textContent.trim()])&&(!$(vl).parent().attr('ignore')))
if ((!unc.hasOwnProperty(vl.textContent.trim()))&&(!$(vl).parent().attr('ignore')))
$(vl).parent().removeAttr('hidden');
});
checkMatch(e);
Expand Down Expand Up @@ -395,6 +395,8 @@ function submit(){ //Collects entered translations for missing tag
ignore.push(v.id); //Mark hidden tags as ignored
return true;
};
if ($(v).parent().attr('hidden'))
return true;
tg=$(v).find('input.txt');
if (tg.length)
tg=tg[0].value.trim(); //found translation tag
Expand Down
2 changes: 1 addition & 1 deletion !Firefox addon/contents/data/animage-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// ==UserScript==
// @name Animage-post
// @description Store tags for images and indicate saved state
// @version 1.3
// @version 1.3.1
// @author Seedmanc
// @namespace https://github.com/Seedmanc/Tumblr-image-sorter

Expand Down
2 changes: 1 addition & 1 deletion !Firefox addon/contents/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"title": "Tumblr Image Sorter",
"name": "tumblrimagesorter",
"version": "1.3.0",
"version": "1.3.1",
"description": "Saves time on choosing folder and file name for saving tumblr images.",
"main": "index.js",
"author": "Seedmanc",
Expand Down
20 changes: 11 additions & 9 deletions Chrome tampermonkey/animage-get.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Animage-get
// @description Format file name & save path for current image by its tags
// @version 1.2
// @version 1.3.1
// @author Seedmanc
// @namespace https://github.com/Seedmanc/Tumblr-image-sorter

Expand Down Expand Up @@ -331,7 +331,7 @@ function checkMatch(obj,fix){ //Remove trailing whitespace in object
};
} catch (err) {
if (!debug)
alert(err.name+': '+err.message); //Gotta always notify the user
alert(err.name+': '+err.message); //Gotta always notify the user
throw err;
}; //TODO: even more checks here
};
Expand Down Expand Up @@ -368,7 +368,7 @@ function onDOMcontentLoaded(){ //Load plugins and databases

href=document.location.href;
if (href.indexOf('tumblr')==-1) //If not on tumblr
if (!(/(jpe*g|bmp|png|gif)/gi).test(href.split('.').pop())) // check if this is actually an image link
if (!(/(jpe?g|bmp|png|gif)/gi).test(href.split('.').pop())) // check if this is actually an image link
return;
$('img').wrap("<center></center>");
$('body').append(out);
Expand Down Expand Up @@ -435,7 +435,7 @@ function mutex(){ //Check readiness of plugins and databases when
};

function main(){ //Launch tag processing and handle afterwork
$( "<style>"+style.s+"</style>" ).appendTo( "head" ); //assign functions to events and whatnot
$("<style>"+style.s+"</style>" ).appendTo( "head" ); //assign functions to events and whatnot
$('div#output').append(port);
toggleSettings();
$('input#debug').prop('checked',debug);
Expand Down Expand Up @@ -508,7 +508,7 @@ function analyzeTags() { //This is where the tag matching magic o
});
//1st sorting stage, no prior knowledge about found categories
$.each(tags, function(i,v){ //Divide tags for the image into 5 categories
if (folders[v]) // the "has folder" category
if (folders.hasOwnProperty(v)) // the "has folder" category
fldrs.push(folders[v])
else if (names.get(v)) // the "no folder name tag" category
nms.push(names.get(v))
Expand All @@ -525,13 +525,13 @@ function analyzeTags() { //This is where the tag matching magic o
nms.push(names.get(rvrs)) // try to find database entry for reversed order first,
return true;
}
else if (ansi[rvrs]) // then check for duplicates
else if (ansi.hasOwnProperty(rvrs)) // then check for duplicates
return true;
}
ansi[v]=true;
};
}
else
else
rest.push(v); // finally the "untranslated" category
});
//2nd sorting stage, now we know how many tags of each category there are
Expand Down Expand Up @@ -691,7 +691,7 @@ function selected(e){ //Hide the corresponding roman tag from resul
});
});
$.each(ansi,function(ix,vl){
if ((!knj[vl.textContent.trim()])&&(!$(vl).parent().attr('ignore')))
if ((!knj.hasOwnProperty(vl.textContent.trim()))&&(!$(vl).parent().attr('ignore')))
$(vl).parent().removeAttr('hidden');
});
var test={tag:e.target.value};
Expand All @@ -710,7 +710,7 @@ function mkUniq(arr){ //Sorts an array and ensures uniqueness of it
return arr2.sort(); //I thought key names are already sorted in an object but for some reason they're not
};

function getFileName(fullName, full){ //Source URL processing for filename
function getFileName(fullName, full){ //Source URL processing for filename
full=full || false;
fullName=fullName.replace(/(#|\?).*$/gim,''); //first remove url parameters
if (fullName.indexOf('xuite')!=-1) { //This blog names their images as "(digit).jpg" causing filename collisions
Expand Down Expand Up @@ -761,6 +761,8 @@ function submit(){ //Collects entered translations for missing tag
ignore.push(v.id); //Mark hidden tags as ignored
return true;
};
if ($(v).parent().attr('hidden'))
return true;
tg=$(v).find('input.txt');
if (tg.length)
tg=tg[0].value.trim(); //found translation tag
Expand Down
13 changes: 3 additions & 10 deletions Chrome tampermonkey/animage-post.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Animage-post
// @description Store tags for images and indicate saved state
// @version 1.2
// @version 1.3.1
// @author Seedmanc
// @namespace https://github.com/Seedmanc/Tumblr-image-sorter

Expand Down Expand Up @@ -149,9 +149,9 @@ function loadAndExecute(url, callback){ //Load specified js library a

function main(){ //Search for post IDs on page and call API to get info about them
if (debug)
jQuery("div[id^='SwfStore_animage_']").css('top','0').css('left','0').css("position",'absolute').css('opacity','0.8');
jQuery("div[id^='SwfStore_animage_']").css({'top':'0','left':'0',"position":'absolute','opacity':'0.8'});
else //Bring the flash window in or out of the view depending on the debug mode
jQuery("div[id^='SwfStore_animage_']").css('top','-2000px').css('left','-2000px').css("position",'absolute');
jQuery("div[id^='SwfStore_animage_']").css({'top':'-2000px', 'left':'-2000px', "position":'absolute'});
if (isDash)
posts=jQuery('ol.posts').find('div.post').not('.new_post') //Getting posts on dashboard is straightforward with its constant design,
else { // but outside of it are all kinds of faulty designs, so we have to experiment
Expand Down Expand Up @@ -204,13 +204,6 @@ function mutex(){ //Check readiness of libraries being loaded si
main(); //when everything is loaded, proceed further
}
};

/*if (typeof masonite != 'undefined')
jQuery(window).load(function(){ //some themes require waiting till their own functions finish
onDOMContentLoaded();
})
else
onDOMContentLoaded();*/

function onDOMContentLoaded(){ //Load plugins

Expand Down
8 changes: 4 additions & 4 deletions Opera native/animage-get.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ function onDOMcontentLoaded(){ //load plugins and databases
return;
href=document.location.href;
if (href.indexOf('tumblr')==-1) //if not on tumblr
if (!(/(jpe*g|bmp|png|gif)/gi).test(href.split('.').pop())) //check if this is actually an image link
if (!(/(jpe?g|bmp|png|gif)/gi).test(href.split('.').pop())) //check if this is actually an image link
return;
loadAndExecute("https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js",function(){
$('body')[0].appendChild(out);
Expand Down Expand Up @@ -505,7 +505,7 @@ function analyzeTags() { //this is where the tag matching magic oc
});
//1st sorting stage, no prior knowledge about found categories
$.each(tags, function(i,v){ //divide tags for the image into 5 categories
if (folders[v]) // the "has folder" category
if (folders.hasOwnProperty(v)) // the "has folder" category
fldrs.push(folders[v])
else if (names.get(v)) // the "no folder name tag" category
nms.push(names.get(v))
Expand All @@ -522,7 +522,7 @@ function analyzeTags() { //this is where the tag matching magic oc
nms.push(names.get(rvrs)) //try to find database entry for reversed order first,
return true;
}
else if (ansi[rvrs]) // then check for duplicates
else if (ansi.hasOwnProperty(rvrs)) // then check for duplicates
return true;
}
ansi[v]=true;
Expand Down Expand Up @@ -686,7 +686,7 @@ function selected(inp){ //hide the corresponding roman tag from resu
}
);
$.each(ansi,function(ix,vl){ //I don't even remember how and why this works
if ((!knj[vl.innerText.trim()])&&(!$(vl).parent().attr('ignore')))
if ((!knj.hasOwnProperty(vl.innerText.trim()))&&(!$(vl).parent().attr('ignore')))
$(vl).parent().removeAttr('hidden'); //but it does
}
);
Expand Down
4 changes: 2 additions & 2 deletions Opera native/animage-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ function getID(lnk){ //extract numerical post ID from self-link

function main(){ //search for post IDs on page and call API to get info about them
if (debug)
jQuery("div[id^='SwfStore_animage_']").css('top','0').css('left','0').css("position",'absolute')
jQuery("div[id^='SwfStore_animage_']").css({'top':'0','left':'0',"position":'absolute'})
else //bring the flash window in or out of the view depending on the debug mode
jQuery("div[id^='SwfStore_animage_']").css('top','-2000px').css('left','-2000px').css("position",'absolute');
jQuery("div[id^='SwfStore_animage_']").css({'top':'-2000px','left':'-2000px',"position":'absolute'});
if (isDash)
posts=jQuery('ol.posts').find('div.post').not('.new_post') //getting posts on dashboard is straightforward with its constant design,
else { // but outside of it are all kinds of faulty designs, so we have to experiment
Expand Down

0 comments on commit 89a94fb

Please sign in to comment.