From 0a5e80671e97d018d889d82f029ab23d0803784b Mon Sep 17 00:00:00 2001 From: Yoru Date: Sun, 14 Jul 2024 23:08:00 +0300 Subject: [PATCH 1/5] change faulty translation and translate untranslated ones --- _locales/tr/messages.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/_locales/tr/messages.json b/_locales/tr/messages.json index e53ba0ca..e317e0a4 100644 --- a/_locales/tr/messages.json +++ b/_locales/tr/messages.json @@ -596,7 +596,7 @@ "message": "Varsayılan bağlantı rengi" }, "font": { - "message": "Font" + "message": "Yazı tipi" }, "color_sync": { "message": "Bağlantı rengi eşitlenimi" @@ -857,10 +857,10 @@ } }, "last_searches": { - "message": "Last searches" + "message": "Son aramalar" }, "saved_searches": { - "message": "Saved searches" + "message": "Kaydedilmiş aramalar" }, "everyone": { "message": "Herkese açık", @@ -963,7 +963,7 @@ "message": "Konuşmayı susturmayı geri al" }, "no_big_font": { - "message": "Kısa/popüler tweetler için büyük fontu devre dışı bırak" + "message": "Kısa/popüler tweetler için büyük yazı tipini devre dışı bırak" }, "emoji": { "message": "Emoji" @@ -1401,7 +1401,7 @@ "description": "You should probably use word 'Profile' in your language" }, "tweet_text_font": { - "message": "Tweet yazı fontu" + "message": "Tweet yazı tipi" }, "use_old_default_profile": { "message": "Varsayılan profil fotoğrafını yumurta yap" @@ -1576,7 +1576,7 @@ "message": "Karanlık mod değişkenleri" }, "css_theme_hint": { - "message": "Lütfen 'göz-kanatıcı' veya diğer herhangi rahatsız edici şeyler yapmayın. (Örneğin takip butonunu çok büyük yapmak gibi), bunun yüzünden erişimini kaybedersin.

Senin CSS'in kullanıcının ayarladığı temanın üzerine yazılır.

Resimleri için sadece i.imgur.com, fontlar için de sadece fonts.googleapis.com kullanabilirsin (veya 'daki fontlar).

You can see list of CSS variables here.

To target specific theme you can use .body-dark, .body-pitch-black (pitch black mode will also include .body-dark) and .body-light classes." + "message": "Lütfen 'göz-kanatıcı' veya diğer herhangi rahatsız edici şeyler yapmayın. (Örneğin takip butonunu çok büyük yapmak gibi), bunun yüzünden erişimini kaybedersin.

Senin CSS'in kullanıcının ayarladığı temanın üzerine yazılır.

Resimleri için sadece i.imgur.com, yazı tipleri için de sadece fonts.googleapis.com kullanabilirsin (veya 'daki yazı tiplerini).

You can see list of CSS variables here.

To target specific theme you can use .body-dark, .body-pitch-black (pitch black mode will also include .body-dark) and .body-light classes." }, "profile_colors_moved": { "message": "Renk senkronizasyonunu profiline bağla (Edit butonunun solundaki kalem butonu)." @@ -1817,7 +1817,7 @@ "message": "Eklenti uyumluluk modu (Başka bir eklentinin OldTwitter ile aynı anda çalışmasını istiyorsanız etkinleştirin, eğer eklenti hala çalışmıyorsa bunu kapatın (büyük ihtimalle çalışmayacak), çünkü bu seçenek sayfayı kastırabilir)" }, "enter_custom_font_name": { - "message": "Özel font ismi girin" + "message": "Özel yazı tipi ismi girin" }, "disable_data_saver": { "message": "Veri kaydediciyi mobil verideyken kapatın", From 9c941fb245cb8015351b4841cba70353d4e4f2ba Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 14 Jul 2024 15:16:53 -0700 Subject: [PATCH 2/5] support custom downloader templates --- _locales/en/messages.json | 11 ++++++++++- layouts/settings/index.html | 16 +++++++++++++++- layouts/settings/script.js | 14 +++++++++++++- scripts/helpers.js | 27 +++++++++++++++++++++++---- 4 files changed, 61 insertions(+), 7 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e6a34579..cd9c5e89 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -207,6 +207,15 @@ "save_vars": { "message": "Save variables" }, "custom_css_text": { "message": "Custom CSS to add on every page." }, "save_css": { "message": "Save CSS" }, + "custom_downloadtemplate": { "message": "Custom download template" }, + "custom_downloadtemplate_text": { "message": "Custom download template to use when downloading a tweet." }, + "save_downloadtemplate": { "message": "Save download template" }, + "custom_downloadtemplate_hintName1": { "message": "{user_name}: User's name." }, + "custom_downloadtemplate_hintName2": { "message": "{user_screen_name}: User's account name. (Example: @dril)" }, + "custom_downloadtemplate_hintTime": { "message": "{timestamp}: Tweet's post date & time." }, + "custom_downloadtemplate_hintExtension": { "message": "{extension} - Downloaded tweet's file extension." }, + "custom_downloadtemplate_hintID": { "message": "{id}: Tweet's ID." }, + "custom_downloadtemplate_hintIndex": { "message": "{index}: Index for each file to download. (for posts with multiple media)" }, "error_setting_color": { "message": "Error setting link color" }, "link_color_set": { "message": "Link color set!" }, "retweeted_by": { "message": "Retweeted by" }, @@ -633,4 +642,4 @@ "you_shared_tweet": { "message": "You shared a tweet" }, "user_shared_tweet": { "message": "$NAME$ shared a tweet", "placeholders": { "name": { "content": "Display Name" } } }, "transition_profile_banner": { "message": "Use transition on profile banner" } -} \ No newline at end of file +} diff --git a/layouts/settings/index.html b/layouts/settings/index.html index 938da9c7..b8deb48d 100644 --- a/layouts/settings/index.html +++ b/layouts/settings/index.html @@ -393,6 +393,20 @@

__MSG_custom_css__




+

__MSG_custom_downloadtemplate__


+ __MSG_custom_downloadtemplate_text__
+
__MSG_custom_downloadtemplate_hintName1__ +
__MSG_custom_downloadtemplate_hintName2__ +
__MSG_custom_downloadtemplate_hintTime__ +
__MSG_custom_downloadtemplate_hintExtension__ +
__MSG_custom_downloadtemplate_hintID__ +
__MSG_custom_downloadtemplate_hintIndex__ +

+
+ +
+ +

__MSG_advanced_options__


@@ -437,4 +451,4 @@

__MSG_who_to_follow__


- \ No newline at end of file + diff --git a/layouts/settings/script.js b/layouts/settings/script.js index f86a988e..08cd418b 100644 --- a/layouts/settings/script.js +++ b/layouts/settings/script.js @@ -276,6 +276,8 @@ setTimeout(async () => { let disableFindHotkey = document.getElementById('disable-find-hotkey'); let customCSS = document.getElementById('custom-css'); let customCSSSave = document.getElementById('custom-css-save'); + let customDownloadTemplate = document.getElementById('custom-download'); + let customDownloadTemplateSave = document.getElementById('custom-download-save'); let savePreferredQuality = document.getElementById('save-preferred-quality'); let roundAvatars = document.getElementById('round-avatars-switch'); let modernUI = document.getElementById('modern-ui-switch'); @@ -907,6 +909,13 @@ setTimeout(async () => { console.error("Error saving CSS to DB:", error); }); }); + customDownloadTemplateSave.addEventListener('click', () => { + let val = customDownloadTemplate.value; + + chrome.storage.sync.set({ + customDownloadTemplate: val + }, () => { }); + }); autotranslateLanguageList.addEventListener('change', () => { addAutotranslateLanguage.disabled = autotranslateLanguageList.value === 'select'; }); @@ -1046,6 +1055,9 @@ setTimeout(async () => { writeCSSToDB(vars.customCSS) } customCSS.value = await readCSSFromDB(); + chrome.storage.sync.get("customDownloadTemplate", res => { + customDownloadTemplate.value = res.customDownloadTemplate; + }) document.getElementById('stt-div').hidden = vars.timelineType !== 'algo' && vars.timelineType !== 'algov2'; savePreferredQuality.checked = !!vars.savePreferredQuality; showOriginalImages.checked = !!vars.showOriginalImages; @@ -1281,4 +1293,4 @@ setTimeout(async () => { setInterval(updateUserData, 60000 * 3); setInterval(() => renderDiscovery(false), 60000 * 15); setInterval(renderTrends, 60000 * 5); -}, 50); \ No newline at end of file +}, 50); diff --git a/scripts/helpers.js b/scripts/helpers.js index 72ceefb7..7465e4f6 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -3541,11 +3541,30 @@ async function appendTweet(t, timelineContainer, options = {}) { let ts = new Date(t.created_at).toISOString().split("T")[0]; let extension = url.pathname.split('.').pop(); let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; - let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; - a.download = filename; - a.click(); - a.remove(); + chrome.storage.sync.get("customDownloadTemplate", result => { + let filename = result.customDownloadTemplate; + + // do default download template, if not specified by user + if(filename.length == 0) { + filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; + } else { + filesave_map = { + "user_screen_name": t.user.screen_name, + "user_name": t.user.name, + "extension": extension, + "timestamp": ts, + "id": t.id_str, + "index": _index + }; + filename = filename.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); + } + console.log(`filename: ${filename}`); + a.download = filename; + a.click(); + a.remove(); + }); + }).catch(e => { downloading = false; console.error(e); From d9d694a6f67d4fd71995bd6b5f8b8f57e33a9141 Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 14 Jul 2024 16:55:18 -0700 Subject: [PATCH 3/5] fix saving/loading filename template --- _locales/en/messages.json | 14 ++++++------- layouts/settings/index.html | 2 +- layouts/settings/script.js | 5 ++--- scripts/config.js | 10 +++++++-- scripts/helpers.js | 41 ++++++++++++++++--------------------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index cd9c5e89..794d0d3b 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -208,14 +208,14 @@ "custom_css_text": { "message": "Custom CSS to add on every page." }, "save_css": { "message": "Save CSS" }, "custom_downloadtemplate": { "message": "Custom download template" }, - "custom_downloadtemplate_text": { "message": "Custom download template to use when downloading a tweet." }, + "custom_downloadtemplate_text": { "message": "Allows you to customize the names of the files when downloading a tweet's media." }, "save_downloadtemplate": { "message": "Save download template" }, - "custom_downloadtemplate_hintName1": { "message": "{user_name}: User's name." }, - "custom_downloadtemplate_hintName2": { "message": "{user_screen_name}: User's account name. (Example: @dril)" }, - "custom_downloadtemplate_hintTime": { "message": "{timestamp}: Tweet's post date & time." }, - "custom_downloadtemplate_hintExtension": { "message": "{extension} - Downloaded tweet's file extension." }, - "custom_downloadtemplate_hintID": { "message": "{id}: Tweet's ID." }, - "custom_downloadtemplate_hintIndex": { "message": "{index}: Index for each file to download. (for posts with multiple media)" }, + "custom_downloadtemplate_hintName1": { "message": "{user_name}: User's name." }, + "custom_downloadtemplate_hintName2": { "message": "{user_screen_name}: User's account name. (Example: @dril)" }, + "custom_downloadtemplate_hintTime": { "message": "{timestamp}: Tweet's post date & time." }, + "custom_downloadtemplate_hintExtension": { "message": "{extension}: Downloaded tweet's file extension." }, + "custom_downloadtemplate_hintID": { "message": "{id}: Tweet's ID." }, + "custom_downloadtemplate_hintIndex": { "message": "{index}: Index for each file to download. (for posts with multiple media)" }, "error_setting_color": { "message": "Error setting link color" }, "link_color_set": { "message": "Link color set!" }, "retweeted_by": { "message": "Retweeted by" }, diff --git a/layouts/settings/index.html b/layouts/settings/index.html index b8deb48d..f73df53d 100644 --- a/layouts/settings/index.html +++ b/layouts/settings/index.html @@ -403,7 +403,7 @@

__MSG_custom_downloadtemplate__



__MSG_custom_downloadtemplate_hintIndex__

- +

diff --git a/layouts/settings/script.js b/layouts/settings/script.js index 08cd418b..f63ac4b3 100644 --- a/layouts/settings/script.js +++ b/layouts/settings/script.js @@ -912,6 +912,7 @@ setTimeout(async () => { customDownloadTemplateSave.addEventListener('click', () => { let val = customDownloadTemplate.value; + vars.customDownloadTemplate = val; chrome.storage.sync.set({ customDownloadTemplate: val }, () => { }); @@ -1055,9 +1056,7 @@ setTimeout(async () => { writeCSSToDB(vars.customCSS) } customCSS.value = await readCSSFromDB(); - chrome.storage.sync.get("customDownloadTemplate", res => { - customDownloadTemplate.value = res.customDownloadTemplate; - }) + customDownloadTemplate.value = vars.customDownloadTemplate; document.getElementById('stt-div').hidden = vars.timelineType !== 'algo' && vars.timelineType !== 'algov2'; savePreferredQuality.checked = !!vars.savePreferredQuality; showOriginalImages.checked = !!vars.showOriginalImages; diff --git a/scripts/config.js b/scripts/config.js index 2a952629..d8c48ba9 100644 --- a/scripts/config.js +++ b/scripts/config.js @@ -32,7 +32,7 @@ async function loadVars() { 'acknowledgedCustomizationButton', 'modernUI', 'showExactValues', 'hideTimelineTypes', 'autotranslateLanguages', 'autotranslationMode', 'muteVideos', 'dontPauseVideos', 'showUserPreviewsOnMobile', 'systemDarkMode', 'localizeDigit', 'disableRetweetHotkey', 'disableLikeHotkey', 'disableFindHotkey', 'extensionCompatibilityMode', 'disableDataSaver', 'disableAcceptType', - 'showUserFollowerCountsInLists', 'showQuoteCount', 'hideUnfollowersPage', 'transitionProfileBanner' + 'showUserFollowerCountsInLists', 'showQuoteCount', 'hideUnfollowersPage', 'transitionProfileBanner', 'customDownloadTemplate' ], data => { // default variables if(typeof(data.linkColorsInTL) !== 'boolean') { @@ -77,6 +77,12 @@ async function loadVars() { customCSSVariables: '' }, () => {}); } + if(typeof(data.customDownloadTemplate) !== 'string') { + data.customDownloadTemplate = ''; + chrome.storage.sync.set({ + customDownloadTemplate: '' + }, () => {}); + } if(typeof(data.copyLinksAs) !== 'string') { data.copyLinksAs = 'twitter.com'; chrome.storage.sync.set({ @@ -234,4 +240,4 @@ async function loadVars() { }; console.log(1, vars); -loadVars(); \ No newline at end of file +loadVars(); diff --git a/scripts/helpers.js b/scripts/helpers.js index 7465e4f6..8e074947 100644 --- a/scripts/helpers.js +++ b/scripts/helpers.js @@ -3541,30 +3541,25 @@ async function appendTweet(t, timelineContainer, options = {}) { let ts = new Date(t.created_at).toISOString().split("T")[0]; let extension = url.pathname.split('.').pop(); let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; + let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; + let filename_template = vars.customDownloadTemplate; + + // use the filename from the user's custom download template, if any + if(filename_template && (filename_template.length > 0)) { + const filesave_map = { + "user_screen_name": t.user.screen_name, + "user_name": t.user.name, + "extension": extension, + "timestamp": ts, + "id": t.id_str, + "index": _index + }; + filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); + } - chrome.storage.sync.get("customDownloadTemplate", result => { - let filename = result.customDownloadTemplate; - - // do default download template, if not specified by user - if(filename.length == 0) { - filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; - } else { - filesave_map = { - "user_screen_name": t.user.screen_name, - "user_name": t.user.name, - "extension": extension, - "timestamp": ts, - "id": t.id_str, - "index": _index - }; - filename = filename.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); - } - console.log(`filename: ${filename}`); - a.download = filename; - a.click(); - a.remove(); - }); - + a.download = filename; + a.click(); + a.remove(); }).catch(e => { downloading = false; console.error(e); From 627a8f0f06a59ff486f78e83f4552d614557bde1 Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 14 Jul 2024 17:38:12 -0700 Subject: [PATCH 4/5] update other renderer & english localization --- _locales/en/messages.json | 20 ++++++++++---------- scripts/tweetviewer.js | 24 ++++++++++++++++++++++-- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/_locales/en/messages.json b/_locales/en/messages.json index 794d0d3b..1c5e56b0 100644 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -207,15 +207,6 @@ "save_vars": { "message": "Save variables" }, "custom_css_text": { "message": "Custom CSS to add on every page." }, "save_css": { "message": "Save CSS" }, - "custom_downloadtemplate": { "message": "Custom download template" }, - "custom_downloadtemplate_text": { "message": "Allows you to customize the names of the files when downloading a tweet's media." }, - "save_downloadtemplate": { "message": "Save download template" }, - "custom_downloadtemplate_hintName1": { "message": "{user_name}: User's name." }, - "custom_downloadtemplate_hintName2": { "message": "{user_screen_name}: User's account name. (Example: @dril)" }, - "custom_downloadtemplate_hintTime": { "message": "{timestamp}: Tweet's post date & time." }, - "custom_downloadtemplate_hintExtension": { "message": "{extension}: Downloaded tweet's file extension." }, - "custom_downloadtemplate_hintID": { "message": "{id}: Tweet's ID." }, - "custom_downloadtemplate_hintIndex": { "message": "{index}: Index for each file to download. (for posts with multiple media)" }, "error_setting_color": { "message": "Error setting link color" }, "link_color_set": { "message": "Link color set!" }, "retweeted_by": { "message": "Retweeted by" }, @@ -641,5 +632,14 @@ "anniversary_tweet": { "message": "Do you remember when you joined Twitter? I do!\n#MyTwitterAnniversary" }, "you_shared_tweet": { "message": "You shared a tweet" }, "user_shared_tweet": { "message": "$NAME$ shared a tweet", "placeholders": { "name": { "content": "Display Name" } } }, - "transition_profile_banner": { "message": "Use transition on profile banner" } + "transition_profile_banner": { "message": "Use transition on profile banner" }, + "custom_downloadtemplate": { "message": "Custom download template" }, + "custom_downloadtemplate_text": { "message": "Allows you to customize the names of the files when downloading a tweet's media." }, + "save_downloadtemplate": { "message": "Save download template" }, + "custom_downloadtemplate_hintName1": { "message": "{user_name}: User's name." }, + "custom_downloadtemplate_hintName2": { "message": "{user_screen_name}: User's account name. (Example: @dril)" }, + "custom_downloadtemplate_hintTime": { "message": "{timestamp}: Tweet's post date & time." }, + "custom_downloadtemplate_hintExtension": { "message": "{extension}: Downloaded tweet's file extension." }, + "custom_downloadtemplate_hintID": { "message": "{id}: Tweet's ID." }, + "custom_downloadtemplate_hintIndex": { "message": "{index}: Index for each file to download. (for posts with multiple media)" } } diff --git a/scripts/tweetviewer.js b/scripts/tweetviewer.js index 2e0a378f..d90dd251 100644 --- a/scripts/tweetviewer.js +++ b/scripts/tweetviewer.js @@ -2455,8 +2455,28 @@ class TweetViewer { downloading = false; let a = document.createElement('a'); a.href = URL.createObjectURL(blob); - a.download = media.type === 'photo' ? media.media_url_https.split('/').pop() : media.video_info.variants[0].url.split('/').pop(); - a.download = a.download.split('?')[0]; + + let ts = new Date(t.created_at).toISOString().split("T")[0]; + let extension = url.split('.').pop(); + //let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; + let _index = 1; + let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; + let filename_template = vars.customDownloadTemplate; + + // use the filename from the user's custom download template, if any + if(filename_template && (filename_template.length > 0)) { + const filesave_map = { + "user_screen_name": t.user.screen_name, + "user_name": t.user.name, + "extension": extension, + "timestamp": ts, + "id": t.id_str, + "index": _index + }; + filename = filename_template.replace(/\{([\w]+)\}/g, (_, key) => filesave_map[key]); + } + + a.download = filename; a.click(); a.remove(); }).catch(e => { From 1bceeca25b3c758361106a1de634f3ad946f9780 Mon Sep 17 00:00:00 2001 From: "U-FEEL\\suwa" Date: Sun, 14 Jul 2024 17:45:05 -0700 Subject: [PATCH 5/5] keep media index blank --- scripts/tweetviewer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/tweetviewer.js b/scripts/tweetviewer.js index d90dd251..ee7bec9d 100644 --- a/scripts/tweetviewer.js +++ b/scripts/tweetviewer.js @@ -2459,7 +2459,7 @@ class TweetViewer { let ts = new Date(t.created_at).toISOString().split("T")[0]; let extension = url.split('.').pop(); //let _index = t.extended_entities.media.length > 1 ? "_"+(index+1) : ""; - let _index = 1; + let _index = ""; let filename = `${t.user.screen_name}_${ts}_${t.id_str}${_index}.${extension}`; let filename_template = vars.customDownloadTemplate;