Skip to content

Commit

Permalink
Merge pull request #6 from ddasutein/feature-line-blog
Browse files Browse the repository at this point in the history
Feature: LINE BLOG Support (Version 1.4.0)
  • Loading branch information
ddasutein authored Jan 24, 2020
2 parents 89fd3f4 + 201091a commit 5d79c44
Show file tree
Hide file tree
Showing 10 changed files with 526 additions and 194 deletions.
44 changes: 32 additions & 12 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down Expand Up @@ -76,7 +80,7 @@
"message": "Include Date (Based on System Date)"
},

"settings_twitter_generate_string":{
"settings_generate_string":{
"message": "String generator length"
},

Expand All @@ -92,51 +96,51 @@
"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)"
},

"settings_twitter_dateformat_item_label_short":{
"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)"
},

Expand All @@ -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"
}
}
46 changes: 33 additions & 13 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
"message": "エクステンションを使用するにクッリクをしてます"
},

"error_lineblog_click_blog":{
"message": "画像を保存するにはブログをクリックしてください"
},

"options_header_title":{
"message": "AutoRename設定"
},
Expand Down Expand Up @@ -76,7 +80,7 @@
"message": "日付を含める(システム日付に基づく)"
},

"settings_twitter_generate_string":{
"settings_generate_string":{
"message": "ストリングジェネレーターの長さ"
},

Expand All @@ -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 (短い)"
},

Expand All @@ -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": "ブログを題名含める"
}
}
58 changes: 58 additions & 0 deletions js/DownloadManager.js
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;
}
});
});
108 changes: 108 additions & 0 deletions js/LineBlogContent.js
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!");
}
}

});
}
Loading

0 comments on commit 5d79c44

Please sign in to comment.