Skip to content

Commit

Permalink
Fully implemented ID tracking
Browse files Browse the repository at this point in the history
For sites that had it. Notably, Twitter & Tumblr are lacking
  • Loading branch information
Brawlence committed Jun 19, 2020
1 parent 572e00b commit 491cbc0
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
15 changes: 7 additions & 8 deletions Extension/Background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -253,15 +252,15 @@ 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);

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 + ")");
Expand Down
7 changes: 6 additions & 1 deletion Extension/Parsers/AS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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:"";
}
3 changes: 2 additions & 1 deletion Extension/Parsers/DA.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:"";
}
4 changes: 3 additions & 1 deletion Extension/Parsers/HF.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:"";
}
3 changes: 2 additions & 1 deletion Extension/Parsers/PX.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:"";
}
2 changes: 1 addition & 1 deletion Extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
},
Expand Down
6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 491cbc0

Please sign in to comment.