diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 589906c..4d37303 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -27,6 +27,10 @@ "message": "Click on the tweet to use this extension." }, + "error_lineblog_click_blog":{ + "message": "Click on the blog post to save this image." + }, + "options_header_title":{ "message": "AutoRename Settings" }, @@ -76,7 +80,7 @@ "message": "Include Date (Based on System Date)" }, - "settings_twitter_generate_string":{ + "settings_generate_string":{ "message": "String generator length" }, @@ -92,35 +96,35 @@ "message": "Preferences saved" }, - "settings_twitter_dateformat_item_label_numerical":{ + "settings_dateformat_item_label_numerical":{ "message": "Numerical" }, - "settings_twitter_dateformat_item_label_option_1":{ + "settings_dateformat_item_label_option_1":{ "message": "MM-DD-YYYY (Numerical)" }, - "settings_twitter_dateformat_item_label_option_2":{ + "settings_dateformat_item_label_option_2":{ "message": "DD-MM-YYYY (Numerical)" }, - "settings_twitter_dateformat_item_label_option_3":{ + "settings_dateformat_item_label_option_3":{ "message": "YYYY-MM-DD (Numerical)" }, - "settings_twitter_dateformat_item_label_long":{ + "settings_dateformat_item_label_long":{ "message": "Long" }, - "settings_twitter_dateformat_item_label_option_4":{ + "settings_dateformat_item_label_option_4":{ "message": "MM-DD-YYYY (Long)" }, - "settings_twitter_dateformat_item_label_option_5":{ + "settings_dateformat_item_label_option_5":{ "message": "DD-MM-YYYY (Long)" }, - "settings_twitter_dateformat_item_label_option_6":{ + "settings_dateformat_item_label_option_6":{ "message": "YYYY-MM-DD (Long)" }, @@ -128,15 +132,15 @@ "message": "Short" }, - "settings_twitter_dateformat_item_label_option_7":{ + "settings_dateformat_item_label_option_7":{ "message": "MM-DD-YYYY (Short)" }, - "settings_twitter_dateformat_item_label_option_8":{ + "settings_dateformat_item_label_option_8":{ "message": "DD-MM-YYYY (Short)" }, - "settings_twitter_dateformat_item_label_option_9":{ + "settings_dateformat_item_label_option_9":{ "message": "YYYY-MM-DD (Short)" }, @@ -148,5 +152,21 @@ "settings_twitter_file_extension_png":{ "message": "PNG", "description": "Do not translate" + }, + + "settings_label_lineblog":{ + "message": "LINE BLOG Settings" + }, + + "settings_label_lineblog_description":{ + "message": "Customize LINE BLOG image download parameters" + }, + + "setting_include_lineblog_web_title":{ + "message": "Include website title [LINE BLOG]" + }, + + "setting_include_lineblog_blog_title":{ + "message": "Include blog title" } } \ No newline at end of file diff --git a/_locales/ja/messages.json b/_locales/ja/messages.json index a84554f..3a3f094 100644 --- a/_locales/ja/messages.json +++ b/_locales/ja/messages.json @@ -27,6 +27,10 @@ "message": "エクステンションを使用するにクッリクをしてます" }, + "error_lineblog_click_blog":{ + "message": "画像を保存するにはブログをクリックしてください" + }, + "options_header_title":{ "message": "AutoRename設定" }, @@ -76,7 +80,7 @@ "message": "日付を含める(システム日付に基づく)" }, - "settings_twitter_generate_string":{ + "settings_generate_string":{ "message": "ストリングジェネレーターの長さ" }, @@ -92,51 +96,51 @@ "message": "設定をセーブしました" }, - "settings_twitter_dateformat_item_label_numerical":{ + "settings_dateformat_item_label_numerical":{ "message": "数値的" }, - "settings_twitter_dateformat_item_label_option_1":{ + "settings_dateformat_item_label_option_1":{ "message": "MM-DD-YYYY (数値的)" }, - "settings_twitter_dateformat_item_label_option_2":{ + "settings_dateformat_item_label_option_2":{ "message": "DD-MM-YYYY (数値的)" }, - "settings_twitter_dateformat_item_label_option_3":{ + "settings_dateformat_item_label_option_3":{ "message": "YYYY-MM-DD (数値的)" }, - "settings_twitter_dateformat_item_label_long":{ + "settings_dateformat_item_label_long":{ "message": "長い" }, - "settings_twitter_dateformat_item_label_option_4":{ + "settings_dateformat_item_label_option_4":{ "message": "MM-DD-YYYY (長い)" }, - "settings_twitter_dateformat_item_label_option_5":{ + "settings_dateformat_item_label_option_5":{ "message": "DD-MM-YYYY (長い)" }, - "settings_twitter_dateformat_item_label_option_6":{ + "settings_dateformat_item_label_option_6":{ "message": "YYYY-MM-DD (長い)" }, - "settings_twitter_dateformat_item_label_short":{ + "settings_dateformat_item_label_short":{ "message": "短い" }, - "settings_twitter_dateformat_item_label_option_7":{ + "settings_dateformat_item_label_option_7":{ "message": "MM-DD-YYYY (短い)" }, - "settings_twitter_dateformat_item_label_option_8":{ + "settings_dateformat_item_label_option_8":{ "message": "DD-MM-YYYY (短い)" }, - "settings_twitter_dateformat_item_label_option_9":{ + "settings_dateformat_item_label_option_9":{ "message": "YYYY-MM-DD (短い)" }, @@ -148,5 +152,21 @@ "settings_twitter_file_extension_png":{ "message": "PNG", "description": "Do not translate" + }, + + "settings_label_lineblog":{ + "message": "LINE BLOG設定" + }, + + "settings_label_lineblog_description":{ + "message": "LINE BLOGイメージのダウンロードパラメーターをカスタマイズする" + }, + + "setting_include_lineblog_web_title":{ + "message": "ウェブサイトを題名含める【LINE BLOG】" + }, + + "setting_include_lineblog_blog_title":{ + "message": "ブログを題名含める" } } \ No newline at end of file diff --git a/js/DownloadManager.js b/js/DownloadManager.js new file mode 100644 index 0000000..43ae240 --- /dev/null +++ b/js/DownloadManager.js @@ -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; + } + }); +}); \ No newline at end of file diff --git a/js/LineBlogContent.js b/js/LineBlogContent.js new file mode 100644 index 0000000..f0fbad7 --- /dev/null +++ b/js/LineBlogContent.js @@ -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!"); + } + } + + }); +} \ No newline at end of file diff --git a/js/SetTimeDate.js b/js/SetTimeDate.js new file mode 100644 index 0000000..243ec30 --- /dev/null +++ b/js/SetTimeDate.js @@ -0,0 +1,85 @@ +/** 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 + * + */ + + /* Vanilla JavaScript doesn"t know how to count months 🙃 +[0] - January +[1] - February +[2] - March +[3] - April +[4] - May +[5] - June +[6] - July +[7] - August +[8] - September +[9] - October +[10] - November +[11] - December */ +let MonthsInNumber = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]; +let MonthsInLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "13"]; +let MonthsInShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "13"]; + +/* Time & Date */ +function GetDateFormat(DateTimeFormat) { + + const DEBUG_TAG = "GetDateFormat => "; + + if (DevMode){ + console.log(DEBUG_TAG + "DateTimeFormat: " + DateTimeFormat); + } + + const _date = new Date(); + let _finalTimeDateValue = ""; + + switch (DateTimeFormat) { + // 0-2 = Numerical Format + case "0": + _finalTimeDateValue = MonthsInNumber[_date.getMonth()] + "-" + _date.getDate() + "-" + _date.getFullYear(); + break; + case "1": + _finalTimeDateValue = _date.getDate() + "-" + MonthsInNumber[_date.getMonth()] + "-" + _date.getFullYear(); + break; + case "2": + _finalTimeDateValue = _date.getFullYear() + "-" + MonthsInNumber[_date.getMonth()] + "-" + _date.getDate(); + break; + // 3-5 = Long Format + case "3": + _finalTimeDateValue = MonthsInLong[_date.getMonth()] + " " + _date.getDate() + ", " + _date.getFullYear(); + break; + case "4": + _finalTimeDateValue = _date.getDate() + " " + MonthsInLong[_date.getMonth()] + " " + _date.getFullYear(); + break; + case "5": + _finalTimeDateValue = _date.getFullYear() + " " + MonthsInLong[_date.getMonth()] + " " + _date.getDate(); + break; + // 6-8 = Short Format + case "6": + _finalTimeDateValue = MonthsInShort[_date.getMonth()] + ". " + _date.getDate() + ", " + _date.getFullYear(); + break; + case "7": + _finalTimeDateValue = _date.getDate() + " " + MonthsInShort[_date.getMonth()] + ". " + _date.getFullYear(); + break; + case "8": + _finalTimeDateValue = _date.getFullYear() + " " + MonthsInShort[_date.getMonth()] + ". " + _date.getDate(); + break; + default: + _finalTimeDateValue = null; + break; + } + + if (DevMode){ + console.log(DEBUG_TAG + "finalTimeDateValue: " + _finalTimeDateValue); + } + + return " (" + _finalTimeDateValue + ")"; +} \ No newline at end of file diff --git a/js/SplitURL.js b/js/SplitURL.js new file mode 100644 index 0000000..a21f3a6 --- /dev/null +++ b/js/SplitURL.js @@ -0,0 +1,23 @@ +/** 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 + * + */ + + /** + * Take the URL and choose a string by entering a number starting from 0 + * @param {*} url + * @param {*} index + */ + function SplitURL(url, index){ + let split = url.split("/"); + return split[index]; + } \ No newline at end of file diff --git a/js/options.js b/js/options.js index 2e7170e..159aa43 100644 --- a/js/options.js +++ b/js/options.js @@ -11,6 +11,13 @@ function SaveOptions() { let useDate = document.getElementById("IsUsingDateCheckbox").checked; let dateFormatting = document.getElementById("DateFormatTypeSelect").value; + // LINE BLOG Settings + let lbPrefIncludeWebsiteTitle = document.getElementById("lineblog_web_title").checked; + let lbPrefIncludeBlogTitle = document.getElementById("lineblog_include_title").checked; + let lbPrefUseDate = document.getElementById("lineblog_IsUsingDateCheckbox").checked; + let lbPrefDateFormatting = document.getElementById("lineblog_date_format").value; + let lbPrefStringGenerator = document.getElementById("lineblog_string_length").value; + chrome.storage.local.set({ // General Settings showDownloadFolderCheckbox: showDownloadFolderCheckbox, @@ -21,7 +28,14 @@ function SaveOptions() { showTweetId: includeTweetId, twitterFileExtensionType: twitterFileExtensionType, useDate: useDate, - dateFormatting: dateFormatting + dateFormatting: dateFormatting, + + // LINE BLOG + lbPrefIncludeWebsiteTitle: lbPrefIncludeWebsiteTitle, + lbPrefIncludeBlogTitle: lbPrefIncludeBlogTitle, + lbPrefUseDate: lbPrefUseDate, + lbPrefDateFormat: lbPrefDateFormatting, + lbPrefStringGenerator: lbPrefStringGenerator }, function () { alert(chrome.i18n.getMessage("settings_save_success")); @@ -39,7 +53,14 @@ function LoadOptions() { showTweetId: true, twitterFileExtensionType: ".jpg", useDate: false, - dateFormatting: "0" + dateFormatting: "0", + + // LINE BLOG + lbPrefIncludeWebsiteTitle: false, + lbPrefIncludeBlogTitle: false, + lbPrefUseDate: false, + lbPrefDateFormat: "0", + lbPrefStringGenerator: "4" }, function (items) { // General Settings @@ -52,11 +73,19 @@ function LoadOptions() { document.getElementById("twitter_file_extension_type").value = items.twitterFileExtensionType; document.getElementById("IsUsingDateCheckbox").checked = items.useDate; document.getElementById("DateFormatTypeSelect").value = items.dateFormatting; - UseDateFormat(items.useDate); + + // LINE BLOG Settings + document.getElementById("lineblog_web_title").checked = items.lbPrefIncludeWebsiteTitle; + document.getElementById("lineblog_include_title").checked = items.lbPrefIncludeBlogTitle; + document.getElementById("lineblog_IsUsingDateCheckbox").checked = items.lbPrefUseDate; + document.getElementById("lineblog_date_format").value = items.lbPrefDateFormat; + document.getElementById("lineblog_string_length").value = items.lbPrefStringGenerator; + LineBlogUseDateFormat(items.lbPrefUseDate); }); } +// #region Twitter let IsUsingDateChecked = document.getElementById("IsUsingDateCheckbox"); let DateFormatTypeSelect = document.getElementById("DateFormatTypeSelect"); @@ -76,6 +105,30 @@ IsUsingDateChecked.onchange = function () { } } +// #endregion +// #region LINE BLOG +let lineblogIsUsingDateChecked = document.getElementById("lineblog_IsUsingDateCheckbox"); +let lineblogDateFormatTypeSelect = document.getElementById("lineblog_date_format"); + +function LineBlogUseDateFormat(IsUsingDate) { + if (!IsUsingDate) { + lineblogDateFormatTypeSelect.disabled = true; + } else { + lineblogDateFormatTypeSelect.disabled = false; + } +} + +lineblogIsUsingDateChecked.onchange = function () { + if (!!this.checked) { + lineblogDateFormatTypeSelect.disabled = false; + } else { + lineblogDateFormatTypeSelect.disabled = true; + } +} +// #endregion + + + // let IsUsingDateChecked = document.getElementById("IsUsingDateCheckbox"); // let IsUsingTwitterApiDateChecked = document.getElementById("IsUsingTwitterApiDateCheckbox"); // let DateFormatTypeSelect = document.getElementById("DateFormatTypeSelect"); diff --git a/js/saveImageEvent.js b/js/saveImageEvent.js index 218aa8f..b4bb638 100644 --- a/js/saveImageEvent.js +++ b/js/saveImageEvent.js @@ -1,15 +1,14 @@ - /* ---------------------DEBUGGER FUNCTIONS------------------------ */ console.log("Welcome to AutoRename" + "\n" + "GitHub: " + "https://github.com/ddasutein/AutoRename" + "\n" + -"Enable Console Debugging by setting 'ShowDebugger' to TRUE"); +"Enable Console Debugging by setting 'DevMode' to TRUE"); -let ShowDebugger = false; +let DevMode = false; -function Debug_Settings_Value(){ +function Debug_Global_Settings(){ - if (!ShowDebugger){ - console.log("Cannot debug this function. Set ShowDebugger to TRUE"); + if (!DevMode){ + console.log("Cannot debug this function. Set DevMode to TRUE"); }else { chrome.storage.local.get({ // General Settings @@ -21,17 +20,31 @@ function Debug_Settings_Value(){ showTweetId: true, twitterFileExtensionType: ".jpg", useDate: false, - dateFormatting: "0" + dateFormatting: "0", + + // LINE BLOG + lbPrefIncludeWebsiteTitle: false, + lbPrefIncludeBlogTitle: false, + lbPrefUseDate: false, + lbPrefDateFormat: "0", + lbPrefStringGenerator: "4" }, function (items) { console.log("AutoRename Settings" + "\n" + - "ShowDownloadsFolderCheckValue: " + items.showDownloadFolderCheckbox + "\n" + - "TwitterFileNameStringLengthValue: " + items.fileNameStringLength + "\n" + - "TwitterShowMentionSymbolValue " + items.showMentionSymbol + "\n" + - "TwitterShowTweetIdValue: " + items.showMentionSymbol + "\n" + - "TwitterFileExtensionTypeValue: " + items.twitterFileExtensionType + "\n" + - "TwitterIsUsingDateCheckboxValue: " + items.useDate + "\n" + - "TwitterDateFormatTypeSelectValue: " + items.dateFormatting + "\n" + "[GENERAL] ShowDownloadsFolderCheckValue: " + items.showDownloadFolderCheckbox + "\n" + + "-----------------------------------------------------------------------" + "\n" + + "[TWITTER] String Length: " + items.fileNameStringLength + "\n" + + "[TWITTER] Include Mention Symbol " + items.showMentionSymbol + "\n" + + "[TWITTER] Include Tweet ID: " + items.showMentionSymbol + "\n" + + "[TWITTER] File Extension Type: " + items.twitterFileExtensionType + "\n" + + "[TWITTER] Include Date: " + items.useDate + "\n" + + "[TWITTER] Date Format: " + items.dateFormatting + "\n" + + "-----------------------------------------------------------------------" + "\n" + + "[LINE BLOG] Include Website Title: " + items.lbPrefIncludeWebsiteTitle + "\n" + + "[LINE BLOG] Include log Title: " + items.lbPrefIncludeBlogTitle + "\n" + + "[LINE BLOG] Include Date: " + items.lbPrefUseDate + "\n" + + "[LINE BLOG] Date Format: " + items.lbPrefDateFormat + "\n" + + "[LINE BLOG] String Generator Length: " + items.lbPrefStringGenerator ); }); } @@ -65,7 +78,8 @@ const Website = { Instagram: 'instagram.com', Facebook: 'facebook.com', Reddit: 'reddit.com', - LINE_BLOG: 'lineblog.me' + LINE_BLOG: 'lineblog.me', + LINE_BLOG_CDN: 'obs.line-scdn.net' } function GenerateRandomString(length) { @@ -77,78 +91,6 @@ function GenerateRandomString(length) { return random.join(""); } -/* Vanilla JavaScript doesn"t know how to count months 🙃 -[0] - January -[1] - February -[2] - March -[3] - April -[4] - May -[5] - June -[6] - July -[7] - August -[8] - September -[9] - October -[10] - November -[11] - December */ -let MonthsInNumber = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13"]; -let MonthsInLong = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", "13"]; -let MonthsInShort = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "13"]; - -/* Time & Date */ -function GetDateFormat(DateTimeFormat) { - - const DEBUG_TAG = "GetDateFormat => "; - - if (ShowDebugger){ - console.log(DEBUG_TAG + "DateTimeFormat: " + DateTimeFormat); - } - - const _date = new Date(); - let _finalTimeDateValue = ""; - - switch (DateTimeFormat) { - // 0-2 = Numerical Format - case "0": - _finalTimeDateValue = MonthsInNumber[_date.getMonth()] + "-" + _date.getDate() + "-" + _date.getFullYear(); - break; - case "1": - _finalTimeDateValue = _date.getDate() + "-" + MonthsInNumber[_date.getMonth()] + "-" + _date.getFullYear(); - break; - case "2": - _finalTimeDateValue = _date.getFullYear() + "-" + MonthsInNumber[_date.getMonth()] + "-" + _date.getDate(); - break; - // 3-5 = Long Format - case "3": - _finalTimeDateValue = MonthsInLong[_date.getMonth()] + " " + _date.getDate() + ", " + _date.getFullYear(); - break; - case "4": - _finalTimeDateValue = _date.getDate() + " " + MonthsInLong[_date.getMonth()] + " " + _date.getFullYear(); - break; - case "5": - _finalTimeDateValue = _date.getFullYear() + " " + MonthsInLong[_date.getMonth()] + " " + _date.getDate(); - break; - // 6-8 = Short Format - case "6": - _finalTimeDateValue = MonthsInShort[_date.getMonth()] + ". " + _date.getDate() + ", " + _date.getFullYear(); - break; - case "7": - _finalTimeDateValue = _date.getDate() + " " + MonthsInShort[_date.getMonth()] + ". " + _date.getFullYear(); - break; - case "8": - _finalTimeDateValue = _date.getFullYear() + " " + MonthsInShort[_date.getMonth()] + ". " + _date.getDate(); - break; - default: - _finalTimeDateValue = null; - break; - } - - if (ShowDebugger){ - console.log(DEBUG_TAG + "finalTimeDateValue: " + _finalTimeDateValue); - } - - return " (" + _finalTimeDateValue + ")"; -} - /* Paramaters to build file name*/ let FileNameBuilder = { username: null, @@ -179,10 +121,17 @@ function CreateFileName() { chrome.tabs.onUpdated.addListener(function(tabID, changeInfo, tab){ if (changeInfo.status == "complete"){ - if (ShowDebugger){ + if (DevMode){ const DEBUG_TAG = "tabsOnUpdated => "; console.log(DEBUG_TAG + tab.url + " " + tab.title); } + + switch(SplitURL(tab.url, 2)){ + case Website.LINE_BLOG: + LINEBLOGTitle(tab.title); + break; + } + ToggleViewOriginalImageContextMenuVisibility(tab.url) } }); @@ -195,7 +144,7 @@ chrome.tabs.onActiveChanged.addListener(function(){ "currentWindow": true}, function(tabs){ - if (ShowDebugger){ + if (DevMode){ const DEBUG_TAG = "tabsOnActiveChanged => "; console.log(DEBUG_TAG + tabs[0].url); } @@ -242,6 +191,9 @@ chrome.contextMenus.onClicked.addListener(function (info, tab) { SaveTwitterImage(info, currentUrlSplit); } break; + case Website.LINE_BLOG: + LineBlogURL(info.srcUrl, tab.url); + break; default: alert(chrome.i18n.getMessage("error_website_not_supported")); break; @@ -301,7 +253,7 @@ function SaveTwitterImage(info, urlSplit) { return; } else { ParseOriginalMediaUrl(info.srcUrl); - FileDownloadManager(Website.Twitter); + StartDownload(Website.Twitter, finalUrlOutput, CreateFileName()); } }); } @@ -326,7 +278,7 @@ function ParseOriginalMediaUrl(url){ finalImageSource = originalUrl; } - if (ShowDebugger){ + if (DevMode){ const DEBUG_TAG = "ParseOriginalMediaUrl => "; console.log(DEBUG_TAG + "original_url: " + originalUrl); console.log(DEBUG_TAG + "final_url: " + finalImageSource); @@ -335,44 +287,4 @@ function ParseOriginalMediaUrl(url){ finalUrlOutput = finalImageSource; } -/* ---------------------END OF TWITTER FUNCTIONS------------------------ */ - -/* Chrome Download API Manager */ -function FileDownloadManager(website) { - - switch (website) { - case Website.Twitter: - - if (ShowDebugger){ - const DEBUG_TAG = "FileDownloadManager => "; - console.log(DEBUG_TAG + "url: " + finalUrlOutput); - console.log(DEBUG_TAG + "fileName: " + CreateFileName()); - } - - chrome.downloads.download({ - url: finalUrlOutput, - filename: CreateFileName(), - saveAs: true - }); - break; - } -} - -chrome.downloads.onChanged.addListener(function (downloadDelta) { - chrome.storage.local.get({ - showDownloadFolderCheckbox: false - }, function (items) { - if (downloadDelta.state && downloadDelta.state.current == "complete") { - - if (ShowDebugger){ - const DEBUG_TAG = "downloadsOnChangedListener => "; - console.log(DEBUG_TAG + downloadDelta.state.current); - } - - if (items.showDownloadFolderCheckbox === true) { - chrome.downloads.showDefaultFolder(); - } - return; - } - }); -}); \ No newline at end of file +/* ---------------------END OF TWITTER FUNCTIONS------------------------ */ \ No newline at end of file diff --git a/manifest.json b/manifest.json index a8c1901..ccbabd8 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "AutoRename", "short_name": "AutoRename", - "version": "1.3.3", + "version": "1.4.0", "description": "AutoRename can automatically rename downloaded images from the internet.", "default_locale": "en", "manifest_version": 2, @@ -16,6 +16,10 @@ "background": { "scripts": [ + "js/SplitURL.js", + "js/LineBlogContent.js", + "js/SetTimeDate.js", + "js/DownloadManager.js", "js/saveImageEvent.js" ], "persistent": false diff --git a/options.html b/options.html index 1fa3fb6..6ae9c4c 100644 --- a/options.html +++ b/options.html @@ -31,38 +31,94 @@

+
+

+ +

+ + +
+ +
+ +
+ +
+ + +
+ + + +
+ + +
-

- + +
+

+

- - + +
+
- -
- +
- - + + + + + + + + + + + +

- @@ -77,16 +133,9 @@

- - -
- - -

+ +
+