diff --git a/Extension/Background.js b/Extension/Background.js index d8d55b8..5926c1b 100644 --- a/Extension/Background.js +++ b/Extension/Background.js @@ -54,21 +54,20 @@ function parseFilename(failOverName, origin, tabId) { // ! TWITTER — cleaning the name from that trailing flag - for old TWITTER (pre Sep 2019) if (origin === "TW" && ext.indexOf('large') > -1) ext = ext.substring(0, ext.indexOf('large') - 1); - // ! PIXIV — format the name to be WiseTagger-compatible + // ! PIXIV — get the page number (since pixiv_xxxx can hold many images) if (origin === "PX") { - var PXnumber = name.substring(0, name.indexOf('_p')); var PXpage = name.substring(name.indexOf('_p') + 2); var PXthumb = ""; - + if (PXpage.indexOf('master') > -1) { PXpage = PXpage.substring(0, PXpage.indexOf('_master')); - PXthumb = " -THUMBNAIL!- "; // if user wants to save a rescaled thumbnail, add a tag + PXthumb = "-THUMBNAIL!-"; // if user wants to save a rescaled thumbnail, add a tag sir.displayWarning(tabId, "You have requested to save a thumbnail. If you want a full-sized picture instead, either:\n- click on it to enlarge before saving\n- use the \"Save link as...\" context menu option."); }; - name = "pixiv_" + PXnumber + PXthumb + " page_" + PXpage + " "; + name = "page_" + PXpage + PXthumb; } else { - name = ""; // other than PIXIV we don't actually need any info from the name + name = ""; // other than PIXIV we don't actually need any info from the name }; return [name, ext]; @@ -253,7 +252,7 @@ var sir = { if (typeof response === 'undefined') return; // get where that image is hosted on by var tempContainer = document.createElement('a'); // creating an link-type (a) object - tempContainer.href = imageObject.srcUrl; // linking to the item we are about to sav + tempContainer.href = imageObject.srcUrl; // linking to the item we are about to save var imageHost = tempContainer.hostname; var failOverName = imageObject.srcUrl.substring(imageObject.srcUrl.lastIndexOf('/') + 1); @@ -261,7 +260,7 @@ var sir = { if (!validateAnswer(response.origin, imageHost, imageObject.pageUrl)) return; var filenameArray = parseFilename(failOverName, response.origin, tabId); - var name = filenameArray[0] + " " + response.tagString, + var name = response.tagString + " " + filenameArray[0], ext = filenameArray[1]; var resultingFilename = purifiedMerge(name, ext); //console.log("Attempting to download:\n url: " + imageObject.srcUrl + "\n resultingFilename: " + resultingFilename + "\n (length: " + resultingFilename.length + ")"); diff --git a/Extension/Parsers/AS.js b/Extension/Parsers/AS.js index ba1f62e..61455b9 100644 --- a/Extension/Parsers/AS.js +++ b/Extension/Parsers/AS.js @@ -2,6 +2,10 @@ var tagsOrigin = "AS"; var windowDisplacement = 90; +//For somewhat more robust anchoring instead of pre-calculated 35 one can use +//const AS_ID_DISPLACEMENT = document.URL.lastIndexOf('work/')+5; +const AS_ID_DISPLACEMENT = 35; + const styleTargets = "div.tags a, aside div.name a, aside div h1.h3"; function getAuthorHandle() { @@ -23,5 +27,6 @@ function getTags() { }; function getPictureID() { - return ""; + let pic_ID = document.URL.substring(AS_ID_DISPLACEMENT).replace(/[\W]/g, ''); //Artstation IDs contain A-z 0-9 + return (pic_ID)?"artstation_"+pic_ID:""; } \ No newline at end of file diff --git a/Extension/Parsers/DA.js b/Extension/Parsers/DA.js index 23d24bb..7458fd4 100644 --- a/Extension/Parsers/DA.js +++ b/Extension/Parsers/DA.js @@ -26,5 +26,6 @@ function getTags() { }; function getPictureID() { - return ""; + let pic_ID = document.URL.substring(document.URL.lastIndexOf('-')).replace(/[\D]/g, ''); //Deviantart IDs are numbers after last dash + return (pic_ID)?"deviantart_"+pic_ID:""; } \ No newline at end of file diff --git a/Extension/Parsers/HF.js b/Extension/Parsers/HF.js index 9c7f98f..89a4512 100644 --- a/Extension/Parsers/HF.js +++ b/Extension/Parsers/HF.js @@ -28,5 +28,7 @@ function getTags() { //https://www.hentai-foundry.com/pictures/1234 function getPictureID() { - return ""; + let URLwithNoName = document.URL.substring(0,document.URL.lastIndexOf('/')); + let pic_ID = URLwithNoName.substring(URLwithNoName.lastIndexOf('/')).replace(/[\D]/g, ''); + return (pic_ID)?"hfoundry_"+pic_ID:""; } \ No newline at end of file diff --git a/Extension/Parsers/PX.js b/Extension/Parsers/PX.js index 0b2c3ad..f6e9c21 100644 --- a/Extension/Parsers/PX.js +++ b/Extension/Parsers/PX.js @@ -27,5 +27,6 @@ function getTags() { }; function getPictureID() { - return ""; + let pic_ID = document.URL.substring(document.URL.lastIndexOf('/')).replace(/[\D]/g, ''); + return (pic_ID)?"pixiv_"+pic_ID:""; } \ No newline at end of file diff --git a/Extension/manifest.json b/Extension/manifest.json index b226a4a..e41f44d 100644 --- a/Extension/manifest.json +++ b/Extension/manifest.json @@ -22,7 +22,7 @@ "js": ["Parsers/AS.js", "Content.js"] }, { - "matches": ["*://*.pixiv.net/art*", "*://*.pximg.net/*"], + "matches": ["*://*.pixiv.net/*work*", "*://*.pximg.net/*"], "run_at": "document_end", "js": ["Parsers/PX.js", "Content.js"] }, diff --git a/test.js b/test.js index 5f78a48..a7a21d9 100644 --- a/test.js +++ b/test.js @@ -1,10 +1,10 @@ // TODO: Plan & implement proper testing suite var Links_to_test = [ - "https://www.artstation.com/artwork/zARRXD", //Not surprisingly, zARRXD is an ID - "https://deviantart.com/view/787225844", //Original was "https://www.deviantart.com/chrissiezullo/art/Nejire-Hadou-787225844" + "https://www.artstation.com/artwork/zARRXD", //ID tracking implemented + "https://deviantart.com/view/787225844", //ID tracking implemented Original was "https://www.deviantart.com/chrissiezullo/art/Nejire-Hadou-787225844" "https://danbooru.donmai.us/posts/3278046", //ID tracking implemented "https://drawfriends.booru.org/index.php?page=post&s=view&id=99115", //ID tracking implemented - "https://www.hentai-foundry.com/pictures/774805", //Original was "https://www.hentai-foundry.com/pictures/user/BBC-Chan/774805/Elyzabeth-1" + "https://www.hentai-foundry.com/pictures/774805", //ID tracking implemented Original was "https://www.hentai-foundry.com/pictures/user/BBC-Chan/774805/Elyzabeth-1" "http://medicalwhiskey.com/?p=12513", //ID tracking implemented "https://www.pixiv.net/artworks/79196939", //ID tracking implemented "https://blurryken.tumblr.com/post/185528821532/do-you-want-to-share-a-bubble-tea-with-me", //IDK how to