-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ddasutein/feature-line-blog
Feature: LINE BLOG Support (Version 1.4.0)
- Loading branch information
Showing
10 changed files
with
526 additions
and
194 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** MIT License | ||
* | ||
* Copyright (c) 2019 Dasutein | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* See more: https://github.com/ddasutein/AutoRename/blob/master/LICENSE | ||
* | ||
*/ | ||
|
||
/** | ||
* Start downloading file | ||
* @param {String} website | ||
* @param {String} url | ||
* @param {String} filename | ||
*/ | ||
function StartDownload(website, url, filename){ | ||
switch (website){ | ||
|
||
case Website.Twitter: | ||
launchDownload(url, filename); | ||
break; | ||
case Website.LINE_BLOG: | ||
launchDownload(url, filename); | ||
break; | ||
} | ||
|
||
function launchDownload(url, filename){ | ||
chrome.downloads.download({ | ||
url: url, | ||
filename: filename, | ||
saveAs: true | ||
}); | ||
} | ||
} | ||
|
||
chrome.downloads.onChanged.addListener(function (downloadDelta) { | ||
chrome.storage.local.get({ | ||
showDownloadFolderCheckbox: false | ||
}, function (items) { | ||
if (downloadDelta.state && downloadDelta.state.current == "complete") { | ||
|
||
if (DevMode){ | ||
const DEBUG_TAG = "downloadsOnChangedListener => "; | ||
console.log(DEBUG_TAG + downloadDelta.state.current); | ||
} | ||
|
||
if (items.showDownloadFolderCheckbox === true) { | ||
chrome.downloads.showDefaultFolder(); | ||
} | ||
return; | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/** MIT License | ||
* | ||
* Copyright (c) 2019 Dasutein | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software | ||
* and associated documentation files (the "Software"), to deal in the Software without restriction, | ||
* including without limitation the rights to use, copy, modify, merge, publish, distribute, | ||
* sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | ||
* is furnished to do so, subject to the following conditions: | ||
* | ||
* See more: https://github.com/ddasutein/AutoRename/blob/master/LICENSE | ||
* | ||
*/ | ||
|
||
/** For reference in saveImageEvent.js */ | ||
let LineBlogContentJS = { | ||
FinalURL: null, | ||
FileName: null | ||
} | ||
|
||
let LineBlogFileNameArray = []; | ||
|
||
let lineBlogCurrentUrl = null; | ||
let lineBlogTabTitle = null; | ||
|
||
function LINEBLOGTitle(tab){ | ||
let tabTitle = tab.split("-"); | ||
lineBlogTabTitle = tabTitle[1]; | ||
} | ||
|
||
function LineBlogURL(imageURL, currentUrl) { | ||
console.log("LineBlogURL (imageURL)", imageURL); | ||
console.log("LineBlogURL (currentUrl)", currentUrl); | ||
lineBlogCurrentUrl = currentUrl; | ||
|
||
let blogId = SplitURL(lineBlogCurrentUrl, 4); | ||
|
||
if (blogId == ""){ | ||
alert(chrome.i18n.getMessage("error_lineblog_click_blog")); | ||
} | ||
|
||
LINEBlogImageURL(imageURL); | ||
} | ||
|
||
let finalLineBlogURL = null; | ||
|
||
function LINEBlogImageURL(url) { | ||
console.log("LINEBlogImageURL", url); | ||
const getOriginalSize = url.substring(0, url.lastIndexOf("/") + 0); | ||
LineBlogContentJS.FinalURL = getOriginalSize; | ||
|
||
LINEBlogFileBuilder(); | ||
} | ||
|
||
|
||
function LINEBlogFileBuilder(){ | ||
let finalFileName = ''; | ||
const title = SplitURL(lineBlogCurrentUrl, 2); | ||
const username = SplitURL(lineBlogCurrentUrl, 3); | ||
const blogId = SplitURL(lineBlogCurrentUrl, 5); | ||
|
||
const _title = title.replace(".me", ""); | ||
const _blogId = blogId.replace(".html", ""); | ||
|
||
chrome.storage.local.get({ | ||
lbPrefIncludeWebsiteTitle: false, | ||
lbPrefIncludeBlogTitle: false, | ||
lbPrefUseDate: false, | ||
lbPrefDateFormat: "0", | ||
lbPrefStringGenerator: "4" | ||
|
||
}, function(items){ | ||
prefWebsiteTitle = items.lbPrefIncludeWebsiteTitle; | ||
prefBlogTitle = items.lbPrefIncludeBlogTitle; | ||
prefIncludeDate = items.lbPrefUseDate; | ||
prefDateFormatting = items.lbPrefDateFormat; | ||
lbPrefStringGenerator = items.lbPrefStringGenerator; | ||
|
||
prefWebsiteTitle ? LineBlogFileNameArray.push(_title.toUpperCase()) : ''; | ||
LineBlogFileNameArray.push(username); | ||
prefBlogTitle ? LineBlogFileNameArray.push(lineBlogTabTitle) : ''; | ||
LineBlogFileNameArray.push(_blogId); | ||
prefIncludeDate ? LineBlogFileNameArray.push(GetDateFormat(prefDateFormatting)) : ''; | ||
LineBlogFileNameArray.push(GenerateRandomString(lbPrefStringGenerator)); | ||
|
||
DevMode ? console.log("LineBlogFileNameArray") : false; | ||
DevMode ? console.log(LineBlogFileNameArray) : false; | ||
|
||
finalFileName = LineBlogFileNameArray.toString(); | ||
finalFileName = LineBlogFileNameArray.join(", "); | ||
LineBlogContentJS.FileName = finalFileName.replace(/,/g, '').replace(/ /g, "-").toString() + ".jpg"; | ||
|
||
StartDownload(Website.LINE_BLOG, LineBlogContentJS.FinalURL, LineBlogContentJS.FileName); | ||
|
||
// Clear array when finished | ||
while (LineBlogFileNameArray.length > 0){ | ||
DevMode ? console.log("Clearing LineBlogFileNameArray... " + LineBlogFileNameArray) : false; | ||
LineBlogFileNameArray.pop(); | ||
} | ||
|
||
if (DevMode){ | ||
if (LineBlogFileNameArray.length == 0){ | ||
console.log("LineBlogFileNameArray Array Cleared!"); | ||
} | ||
} | ||
|
||
}); | ||
} |
Oops, something went wrong.