Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lyrics-plus): seperate translated lyrics providers from mode selection #2330

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
085a17b
port the lyrics source + lang override to latest
Deskehs May 1, 2023
219fec0
updated spelling
Deskehs May 1, 2023
ddbe653
updated options
Deskehs May 1, 2023
0f5effb
update lyricsSource function
Deskehs May 1, 2023
04832e6
updated language function
Deskehs May 1, 2023
f31bc70
port the lyrics source + lang override to latest
Deskehs May 1, 2023
7611e3b
updated spelling
Deskehs May 1, 2023
7ae3ee8
updated options
Deskehs May 1, 2023
f5c7ff8
update lyricsSource function
Deskehs May 1, 2023
9460d29
updated language function
Deskehs May 1, 2023
e15775b
Merge branch 'force-lang2' of https://github.com/Deskehs/spicetify-cl…
Deskehs May 7, 2023
6c36989
update algorithm + option menu + translate function
Deskehs May 7, 2023
ccaac47
update translation provider netease option name
Deskehs May 7, 2023
1f4e7f1
update desc
Deskehs May 7, 2023
3a0eb8e
feat: modify lyrics cleantitle regex & netease lyrics update (#2319)
Lseoksee May 8, 2023
4e019d7
feat(new-releases): dismissible cards (#2328)
ohitstom May 8, 2023
3783703
feat(fullAppDisplay): add day to album release date (#2336)
Ender-Wang May 9, 2023
34b912a
chore(deps): bump golang.org/x/net from 0.9.0 to 0.10.0 (#2337)
dependabot[bot] May 9, 2023
a71ab9e
fix(update-modal): log error (#2341)
Tetrax-10 May 10, 2023
6f4f105
chore(css-map): add root classes (#2342)
Tetrax-10 May 10, 2023
bb93f96
fix(playbar): add classname when not registered (#2340)
kyrie25 May 10, 2023
131319c
feat(fullAppDisplay): show always the exact releaseDate (#2338)
Ender-Wang May 10, 2023
dd35d5c
try componentdidupdate
Deskehs May 11, 2023
b066cd8
force detect korean when detecting hangul
Deskehs May 11, 2023
9ef0f19
force detect korean when hangul shows up
Deskehs May 11, 2023
2f97d71
prettify
Deskehs May 11, 2023
d826476
port the lyrics source + lang override to latest
Deskehs May 1, 2023
bd807f0
updated spelling
Deskehs May 1, 2023
987e15d
updated options
Deskehs May 1, 2023
6de03a3
update lyricsSource function
Deskehs May 1, 2023
1574a82
updated language function
Deskehs May 1, 2023
896d0fd
update algorithm + option menu + translate function
Deskehs May 7, 2023
f5cfe1c
update translation provider netease option name
Deskehs May 7, 2023
1745bd5
update desc
Deskehs May 7, 2023
fda97a9
try componentdidupdate
Deskehs May 11, 2023
cb7da47
force detect korean when detecting hangul
Deskehs May 11, 2023
aa6373d
force detect korean when hangul shows up
Deskehs May 11, 2023
807e341
prettify
Deskehs May 11, 2023
d61c961
Merge branch 'force-lang2' of https://github.com/Deskehs/spicetify-cl…
Deskehs May 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 34 additions & 9 deletions CustomApps/lyrics-plus/OptionsMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ const TranslationMenu = react.memo(({ showTranslationButton, friendlyLanguage, h

let translator = new Translator();

let menuOptions = null;
let sourceOptions = {
none: "None"
};
const languageOptions = {
off: "Off",
chinese: "Chinese",
japanese: "Japanese",
korean: "Korean"
};
let modeOptions = {};

switch (friendlyLanguage) {
case "japanese": {
menuOptions = {
modeOptions = {
furigana: "Furigana",
romaji: "Romaji",
hiragana: "Hiragana",
Expand All @@ -104,14 +113,14 @@ const TranslationMenu = react.memo(({ showTranslationButton, friendlyLanguage, h
break;
}
case "korean": {
menuOptions = {
modeOptions = {
hangul: "Hangul",
romaja: "Romaja"
};
break;
}
case "chinese": {
menuOptions = {
modeOptions = {
cn: "Simplified Chinese",
hk: "Traditional Chinese (Hong Kong)",
tw: "Traditional Chinese (Taiwan)"
Expand All @@ -120,9 +129,9 @@ const TranslationMenu = react.memo(({ showTranslationButton, friendlyLanguage, h
}
}
if (hasNeteaseTranslation) {
menuOptions = {
...menuOptions,
neteaseTranslation: "Netease"
sourceOptions = {
...sourceOptions,
neteaseTranslation: "Netease (Chinese)"
};
}

Expand All @@ -146,10 +155,24 @@ const TranslationMenu = react.memo(({ showTranslationButton, friendlyLanguage, h
react.createElement(OptionList, {
items: [
{
desc: "Mode",
desc: "Translated Lyrics Provider",
key: `translate:translated-lyrics-source`,
type: ConfigSelection,
options: sourceOptions,
renderInline: true
},
{
desc: "Detect Language Override",
key: `translate:detect-language-override`,
type: ConfigSelection,
options: languageOptions,
renderInline: true
},
{
desc: "Text Display Mode",
key: `translation-mode:${friendlyLanguage}`,
type: ConfigSelection,
options: menuOptions,
options: modeOptions,
renderInline: true
},
{
Expand All @@ -167,6 +190,8 @@ const TranslationMenu = react.memo(({ showTranslationButton, friendlyLanguage, h
lyricContainerUpdate && lyricContainerUpdate();
CONFIG.visual[name] && Spicetify.showNotification("Translating...", false, 5000);
translator.injectExternals();
// run the translate function after user changes translate lyrics source
// update the dropdowns
}
})
),
Expand Down
2 changes: 1 addition & 1 deletion CustomApps/lyrics-plus/ProviderNetease.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const ProviderNetease = (function () {
"\\s?作?\\s*词|\\s?作?\\s*曲|\\s?编\\s*曲?|\\s?监\\s*制?",
".*编写|.*和音|.*和声|.*合声|.*提琴|.*录|.*工程|.*工作室|.*设计|.*剪辑|.*制作|.*发行|.*出品|.*后期|.*混音|.*缩混",
"原唱|翻唱|题字|文案|海报|古筝|二胡|钢琴|吉他|贝斯|笛子|鼓|弦乐",
"lrc|publish|vocal|guitar|program|produce|write"
"lrc|publish|vocal|guitar|program|produce|write|mix"
];
const creditInfoRegExp = new RegExp(`^(${creditInfo.join("|")}).*(:|:)`, "i");

Expand Down
4 changes: 2 additions & 2 deletions CustomApps/lyrics-plus/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,8 +522,8 @@ function openConfig() {
when: () => !CONFIG.visual["colorful"]
},
{
desc: "Text convertion: Chinese-Japanese Detection threshold (Advanced)",
info: "Checks if whenever Hanzi/Kanji or Kana is dominant in lyrics. If the result passes the threshold, it's most likely Japanese, and vice versa. This setting is in percentage.",
desc: "Text convertion: Japanese Detection threshold (Advanced)",
info: "Checks if whenever Kana is dominant in lyrics. If the result passes the threshold, it's most likely Japanese, and vice versa. This setting is in percentage.",
key: "ja-detect-threshold",
type: ConfigAdjust,
min: thresholdSizeLimit.min,
Expand Down
32 changes: 12 additions & 20 deletions CustomApps/lyrics-plus/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Utils {
static removeSongFeat(s) {
return (
s
.replace(/-\s+(feat|with).*/i, "")
.replace(/(\(|\[)(feat|with)\.?\s+.*(\)|\])$/i, "")
.replace(/-\s+(feat|with|prod).*/i, "")
.replace(/(\(|\[)(feat|with|prod)\.?\s+.*(\)|\])$/i, "")
.trim() || s
);
}
Expand All @@ -57,6 +57,8 @@ class Utils {

static detectLanguage(lyrics) {
// Should return IETF BCP 47 language tags.
// This should detect the song's main language.
// Remember there is a possibility of a song referencing something in another language and the lyrics show it in that native language!
const rawLyrics = lyrics.map(line => line.text).join(" ");

const kanaRegex = /[\u3001-\u3003]|[\u3005\u3007]|[\u301d-\u301f]|[\u3021-\u3035]|[\u3038-\u303a]|[\u3040-\u30ff]|[\uff66-\uff9f]/gu;
Expand All @@ -67,32 +69,22 @@ class Utils {
/[萬與醜專業叢東絲丟兩嚴喪個爿豐臨為麗舉麼義烏樂喬習鄉書買亂爭於虧雲亙亞產畝親褻嚲億僅從侖倉儀們價眾優夥會傴傘偉傳傷倀倫傖偽佇體餘傭僉俠侶僥偵側僑儈儕儂俁儔儼倆儷儉債傾傯僂僨償儻儐儲儺兒兌兗黨蘭關興茲養獸囅內岡冊寫軍農塚馮衝決況凍淨淒涼淩減湊凜幾鳳鳧憑凱擊氹鑿芻劃劉則剛創刪別剗剄劊劌剴劑剮劍剝劇勸辦務勱動勵勁勞勢勳猛勩勻匭匱區醫華協單賣盧鹵臥衛卻巹廠廳曆厲壓厭厙廁廂厴廈廚廄廝縣參靉靆雙發變敘疊葉號歎嘰籲後嚇呂嗎唚噸聽啟吳嘸囈嘔嚦唄員咼嗆嗚詠哢嚨嚀噝吒噅鹹呱響啞噠嘵嗶噦嘩噲嚌噥喲嘜嗊嘮啢嗩唕喚呼嘖嗇囀齧囉嘽嘯噴嘍嚳囁嗬噯噓嚶囑嚕劈囂謔團園囪圍圇國圖圓聖壙場阪壞塊堅壇壢壩塢墳墜壟壟壚壘墾坰堊墊埡墶壋塏堖塒塤堝墊垵塹墮壪牆壯聲殼壺壼處備複夠頭誇夾奪奩奐奮獎奧妝婦媽嫵嫗媯姍薑婁婭嬈嬌孌娛媧嫻嫿嬰嬋嬸媼嬡嬪嬙嬤孫學孿寧寶實寵審憲宮寬賓寢對尋導壽將爾塵堯尷屍盡層屭屜屆屬屢屨嶼歲豈嶇崗峴嶴嵐島嶺嶽崠巋嶨嶧峽嶢嶠崢巒嶗崍嶮嶄嶸嶔崳嶁脊巔鞏巰幣帥師幃帳簾幟帶幀幫幬幘幗冪襆幹並廣莊慶廬廡庫應廟龐廢廎廩開異棄張彌弳彎彈強歸當錄彠彥徹徑徠禦憶懺憂愾懷態慫憮慪悵愴憐總懟懌戀懇惡慟懨愷惻惱惲悅愨懸慳憫驚懼慘懲憊愜慚憚慣湣慍憤憒願懾憖怵懣懶懍戇戔戲戧戰戩戶紮撲扡執擴捫掃揚擾撫拋摶摳掄搶護報擔擬攏揀擁攔擰撥擇掛摯攣掗撾撻挾撓擋撟掙擠揮撏撈損撿換搗據撚擄摑擲撣摻摜摣攬撳攙擱摟攪攜攝攄擺搖擯攤攖撐攆擷擼攛擻攢敵斂數齋斕鬥斬斷無舊時曠暘曇晝曨顯晉曬曉曄暈暉暫曖劄術樸機殺雜權條來楊榪傑極構樅樞棗櫪梘棖槍楓梟櫃檸檉梔柵標棧櫛櫳棟櫨櫟欄樹棲樣欒棬椏橈楨檔榿橋樺檜槳樁夢檮棶檢欞槨櫝槧欏橢樓欖櫬櫚櫸檟檻檳櫧橫檣櫻櫫櫥櫓櫞簷檁歡歟歐殲歿殤殘殞殮殫殯毆毀轂畢斃氈毿氌氣氫氬氳彙漢汙湯洶遝溝沒灃漚瀝淪滄渢溈滬濔濘淚澩瀧瀘濼瀉潑澤涇潔灑窪浹淺漿澆湞溮濁測澮濟瀏滻渾滸濃潯濜塗湧濤澇淶漣潿渦溳渙滌潤澗漲澀澱淵淥漬瀆漸澠漁瀋滲溫遊灣濕潰濺漵漊潷滾滯灩灄滿瀅濾濫灤濱灘澦濫瀠瀟瀲濰潛瀦瀾瀨瀕灝滅燈靈災燦煬爐燉煒熗點煉熾爍爛烴燭煙煩燒燁燴燙燼熱煥燜燾煆糊溜愛爺牘犛牽犧犢強狀獷獁猶狽麅獮獰獨狹獅獪猙獄猻獫獵獼玀豬貓蝟獻獺璣璵瑒瑪瑋環現瑲璽瑉玨琺瓏璫琿璡璉瑣瓊瑤璦璿瓔瓚甕甌電畫暢佘疇癤療瘧癘瘍鬁瘡瘋皰屙癰痙癢瘂癆瘓癇癡癉瘮瘞瘺癟癱癮癭癩癬癲臒皚皺皸盞鹽監蓋盜盤瞘眥矓著睜睞瞼瞞矚矯磯礬礦碭碼磚硨硯碸礪礱礫礎硜矽碩硤磽磑礄確鹼礙磧磣堿镟滾禮禕禰禎禱禍稟祿禪離禿稈種積稱穢穠穭稅穌穩穡窮竊竅窯竄窩窺竇窶豎競篤筍筆筧箋籠籩築篳篩簹箏籌簽簡籙簀篋籜籮簞簫簣簍籃籬籪籟糴類秈糶糲粵糞糧糝餱緊縶糸糾紆紅紂纖紇約級紈纊紀紉緯紜紘純紕紗綱納紝縱綸紛紙紋紡紵紖紐紓線紺絏紱練組紳細織終縐絆紼絀紹繹經紿綁絨結絝繞絰絎繪給絢絳絡絕絞統綆綃絹繡綌綏絛繼綈績緒綾緓續綺緋綽緔緄繩維綿綬繃綢綯綹綣綜綻綰綠綴緇緙緗緘緬纜緹緲緝縕繢緦綞緞緶線緱縋緩締縷編緡緣縉縛縟縝縫縗縞纏縭縊縑繽縹縵縲纓縮繆繅纈繚繕繒韁繾繰繯繳纘罌網羅罰罷羆羈羥羨翹翽翬耮耬聳恥聶聾職聹聯聵聰肅腸膚膁腎腫脹脅膽勝朧腖臚脛膠脈膾髒臍腦膿臠腳脫腡臉臘醃膕齶膩靦膃騰臏臢輿艤艦艙艫艱豔艸藝節羋薌蕪蘆蓯葦藶莧萇蒼苧蘇檾蘋莖蘢蔦塋煢繭荊薦薘莢蕘蓽蕎薈薺蕩榮葷滎犖熒蕁藎蓀蔭蕒葒葤藥蒞蓧萊蓮蒔萵薟獲蕕瑩鶯蓴蘀蘿螢營縈蕭薩蔥蕆蕢蔣蔞藍薊蘺蕷鎣驀薔蘞藺藹蘄蘊藪槁蘚虜慮虛蟲虯蟣雖蝦蠆蝕蟻螞蠶蠔蜆蠱蠣蟶蠻蟄蛺蟯螄蠐蛻蝸蠟蠅蟈蟬蠍螻蠑螿蟎蠨釁銜補襯袞襖嫋褘襪襲襏裝襠褌褳襝褲襇褸襤繈襴見觀覎規覓視覘覽覺覬覡覿覥覦覯覲覷觴觸觶讋譽謄訁計訂訃認譏訐訌討讓訕訖訓議訊記訒講諱謳詎訝訥許訛論訩訟諷設訪訣證詁訶評詛識詗詐訴診詆謅詞詘詔詖譯詒誆誄試詿詩詰詼誠誅詵話誕詬詮詭詢詣諍該詳詫諢詡譸誡誣語誚誤誥誘誨誑說誦誒請諸諏諾讀諑誹課諉諛誰諗調諂諒諄誶談誼謀諶諜謊諫諧謔謁謂諤諭諼讒諮諳諺諦謎諞諝謨讜謖謝謠謗諡謙謐謹謾謫譾謬譚譖譙讕譜譎讞譴譫讖穀豶貝貞負貟貢財責賢敗賬貨質販貪貧貶購貯貫貳賤賁貰貼貴貺貸貿費賀貽賊贄賈賄貲賃賂贓資賅贐賕賑賚賒賦賭齎贖賞賜贔賙賡賠賧賴賵贅賻賺賽賾贗讚贇贈贍贏贛赬趙趕趨趲躉躍蹌蹠躒踐躂蹺蹕躚躋踴躊蹤躓躑躡蹣躕躥躪躦軀車軋軌軒軑軔轉軛輪軟轟軲軻轤軸軹軼軤軫轢軺輕軾載輊轎輈輇輅較輒輔輛輦輩輝輥輞輬輟輜輳輻輯轀輸轡轅轄輾轆轍轔辭辯辮邊遼達遷過邁運還這進遠違連遲邇逕跡適選遜遞邐邏遺遙鄧鄺鄔郵鄒鄴鄰鬱郤郟鄶鄭鄆酈鄖鄲醞醱醬釅釃釀釋裏钜鑒鑾鏨釓釔針釘釗釙釕釷釺釧釤鈒釩釣鍆釹鍚釵鈃鈣鈈鈦鈍鈔鍾鈉鋇鋼鈑鈐鑰欽鈞鎢鉤鈧鈁鈥鈄鈕鈀鈺錢鉦鉗鈷缽鈳鉕鈽鈸鉞鑽鉬鉭鉀鈿鈾鐵鉑鈴鑠鉛鉚鈰鉉鉈鉍鈹鐸鉶銬銠鉺銪鋏鋣鐃銍鐺銅鋁銱銦鎧鍘銖銑鋌銩銛鏵銓鉿銚鉻銘錚銫鉸銥鏟銃鐋銨銀銣鑄鐒鋪鋙錸鋱鏈鏗銷鎖鋰鋥鋤鍋鋯鋨鏽銼鋝鋒鋅鋶鐦鐧銳銻鋃鋟鋦錒錆鍺錯錨錡錁錕錩錫錮鑼錘錐錦鍁錈錇錟錠鍵鋸錳錙鍥鍈鍇鏘鍶鍔鍤鍬鍾鍛鎪鍠鍰鎄鍍鎂鏤鎡鏌鎮鎛鎘鑷鐫鎳鎿鎦鎬鎊鎰鎔鏢鏜鏍鏰鏞鏡鏑鏃鏇鏐鐔钁鐐鏷鑥鐓鑭鐠鑹鏹鐙鑊鐳鐶鐲鐮鐿鑔鑣鑞鑲長門閂閃閆閈閉問闖閏闈閑閎間閔閌悶閘鬧閨聞闥閩閭闓閥閣閡閫鬮閱閬闍閾閹閶鬩閿閽閻閼闡闌闃闠闊闋闔闐闒闕闞闤隊陽陰陣階際陸隴陳陘陝隉隕險隨隱隸雋難雛讎靂霧霽黴靄靚靜靨韃鞽韉韝韋韌韍韓韙韞韜韻頁頂頃頇項順須頊頑顧頓頎頒頌頏預顱領頗頸頡頰頲頜潁熲頦頤頻頮頹頷頴穎顆題顒顎顓顏額顳顢顛顙顥纇顫顬顰顴風颺颭颮颯颶颸颼颻飀飄飆飆飛饗饜飣饑飥餳飩餼飪飫飭飯飲餞飾飽飼飿飴餌饒餉餄餎餃餏餅餑餖餓餘餒餕餜餛餡館餷饋餶餿饞饁饃餺餾饈饉饅饊饌饢馬馭馱馴馳驅馹駁驢駔駛駟駙駒騶駐駝駑駕驛駘驍罵駰驕驊駱駭駢驫驪騁驗騂駸駿騏騎騍騅騌驌驂騙騭騤騷騖驁騮騫騸驃騾驄驏驟驥驦驤髏髖髕鬢魘魎魚魛魢魷魨魯魴魺鮁鮃鯰鱸鮋鮓鮒鮊鮑鱟鮍鮐鮭鮚鮳鮪鮞鮦鰂鮜鱠鱭鮫鮮鮺鯗鱘鯁鱺鰱鰹鯉鰣鰷鯀鯊鯇鮶鯽鯒鯖鯪鯕鯫鯡鯤鯧鯝鯢鯰鯛鯨鯵鯴鯔鱝鰈鰏鱨鯷鰮鰃鰓鱷鰍鰒鰉鰁鱂鯿鰠鼇鰭鰨鰥鰩鰟鰜鰳鰾鱈鱉鰻鰵鱅鰼鱖鱔鱗鱒鱯鱤鱧鱣鳥鳩雞鳶鳴鳲鷗鴉鶬鴇鴆鴣鶇鸕鴨鴞鴦鴒鴟鴝鴛鴬鴕鷥鷙鴯鴰鵂鴴鵃鴿鸞鴻鵐鵓鸝鵑鵠鵝鵒鷳鵜鵡鵲鶓鵪鶤鵯鵬鵮鶉鶊鵷鷫鶘鶡鶚鶻鶿鶥鶩鷊鷂鶲鶹鶺鷁鶼鶴鷖鸚鷓鷚鷯鷦鷲鷸鷺鸇鷹鸌鸏鸛鸘鹺麥麩黃黌黶黷黲黽黿鼂鼉鞀鼴齇齊齏齒齔齕齗齟齡齙齠齜齦齬齪齲齷龍龔龕龜誌製谘隻裡係範鬆冇嚐嘗鬨麵準鐘彆閒乾儘臟拚]/gu;

const cjkMatch = rawLyrics.match(new RegExp(kanaRegex.source + "|" + /\p{Unified_Ideograph}/gu.source + "|" + hangulRegex.source, "gu"));
let kanaCount = 0;
let tradCount = 0;
let simpCount = 0;

if (!cjkMatch) return;

for (const character of cjkMatch) {
if (character.match(hangulRegex)) {
return "ko";
}
if (character.match(kanaRegex)) {
kanaCount++;
}
if (character.match(simpRegex)) {
simpCount++;
}
if (character.match(tradRegex)) {
tradCount++;
}
}
const kanaCount = cjkMatch.filter(glyph => kanaRegex.test(glyph)).length;
const simpCount = cjkMatch.filter(glyph => simpRegex.test(glyph)).length;
const tradCount = cjkMatch.filter(glyph => tradRegex.test(glyph)).length;

const kanaPercentage = kanaCount / cjkMatch.length;
const simpPercentage = simpCount / cjkMatch.length;
const tradPercentage = tradCount / cjkMatch.length;

if (((kanaPercentage - (simpPercentage + tradPercentage) + 1) / 2) * 100 >= CONFIG.visual["ja-detect-threshold"]) {
if (cjkMatch.filter(glyph => hangulRegex.test(glyph))) {
return "ko";
}

if (((kanaPercentage - (1 - kanaPercentage) + 1) / 2) * 100 >= CONFIG.visual["ja-detect-threshold"]) {
return "ja";
}

Expand Down
37 changes: 32 additions & 5 deletions CustomApps/lyrics-plus/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const CONFIG = {
["lines-before"]: localStorage.getItem("lyrics-plus:visual:lines-before") || "0",
["lines-after"]: localStorage.getItem("lyrics-plus:visual:lines-after") || "2",
["font-size"]: localStorage.getItem("lyrics-plus:visual:font-size") || "32",
["translate:translated-lyrics-source"]: localStorage.getItem("lyrics-plus:visual:translate:translated-lyrics-source") || "none",
["translate:detect-language-override"]: localStorage.getItem("lyrics-plus:visual:translate:detect-language-override") || "off",
["translation-mode:japanese"]: localStorage.getItem("lyrics-plus:visual:translation-mode:japanese") || "furigana",
["translation-mode:korean"]: localStorage.getItem("lyrics-plus:visual:translation-mode:korean") || "hangul",
["translation-mode:chinese"]: localStorage.getItem("lyrics-plus:visual:translation-mode:chinese") || "cn",
Expand Down Expand Up @@ -339,13 +341,23 @@ class LyricsContainer extends react.Component {
this.translateLyrics();
}

lyricsSource(state) {
switch (CONFIG.visual["translate:translated-lyrics-source"]) {
case "neteaseTranslation": {
if (this.state.neteaseTranslation !== null) return this.state.neteaseTranslation;
break;
}
}
return state;
}

async translateLyrics() {
if (!this.translator || !this.translator.finished) {
setTimeout(this.translateLyrics.bind(this), 100);
return;
}

const lyricsToTranslate = this.state.synced ?? this.state.unsynced;
const lyricsToTranslate = this.lyricsSource(this.state.synced ?? this.state.unsynced);

if (!lyricsToTranslate) return;

Expand Down Expand Up @@ -589,6 +601,14 @@ class LyricsContainer extends react.Component {
this.mousetrap.bind(CONFIG.visual["fullscreen-key"], this.toggleFullscreen);
}

componentDidUpdate(prevProps, prevState) {
console.log(this.state);
console.log(prevState);
if (CONFIG.visual["translate:translated-lyrics-source"] !== "none" && this.state !== prevState) {
this.translateLyrics();
}
}

render() {
const fadLyricsContainer = document.getElementById("fad-lyrics-plus-container");
this.state.isFADMode = !!fadLyricsContainer;
Expand Down Expand Up @@ -632,9 +652,16 @@ class LyricsContainer extends react.Component {
}

const hasNeteaseTranslation = this.state.neteaseTranslation !== null;
const language = (this.state.synced || this.state.unsynced) && Utils.detectLanguage(this.state.synced || this.state.unsynced);
const language = () => {
if (!this.state.synced || !this.state.unsynced) return;
if ([CONFIG.visual["translate:detect-language-override"]] == "off") {
return Utils.detectLanguage(this.lyricsSource(this.state.synced || this.state.unsynced));
}
return CONFIG.visual["translate:detect-language-override"];
};
console.log(language());
const languageDisplayNames = new Intl.DisplayNames(["en"], { type: "language" });
const friendlyLanguage = language && languageDisplayNames.of(language.split("-")[0]).toLowerCase();
const friendlyLanguage = language() && languageDisplayNames.of(language().split("-")[0]).toLowerCase();
const showTranslationButton = (friendlyLanguage || hasNeteaseTranslation) && (mode == SYNCED || mode == UNSYNCED);
const translatedLyrics = this.state[CONFIG.visual[`translation-mode:${friendlyLanguage}`]];

Expand All @@ -652,14 +679,14 @@ class LyricsContainer extends react.Component {
} else if (mode === SYNCED && this.state.synced) {
activeItem = react.createElement(CONFIG.visual["synced-compact"] ? SyncedLyricsPage : SyncedExpandedLyricsPage, {
trackUri: this.state.uri,
lyrics: CONFIG.visual["translate"] && translatedLyrics ? translatedLyrics : this.state.synced,
lyrics: CONFIG.visual["translate"] && translatedLyrics ? translatedLyrics : this.lyricsSource(this.state.synced),
provider: this.state.provider,
copyright: this.state.copyright
});
} else if (mode === UNSYNCED && this.state.unsynced) {
activeItem = react.createElement(UnsyncedLyricsPage, {
trackUri: this.state.uri,
lyrics: CONFIG.visual["translate"] && translatedLyrics ? translatedLyrics : this.state.unsynced,
lyrics: CONFIG.visual["translate"] && translatedLyrics ? translatedLyrics : this.lyricsSource(this.state.unsynced),
provider: this.state.provider,
copyright: this.state.copyright
});
Expand Down
34 changes: 33 additions & 1 deletion CustomApps/new-releases/Card.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class Card extends react.Component {
event.stopPropagation();
}

closeButtonClicked(event) {
removeCards(this.props.uri);
Spicetify.showNotification(`Dismissed <b>${this.title}</b> from <b>${this.artist.name}</b>`);
event.stopPropagation();
}

render() {
let detail = [];
this.visual.type && detail.push(this.type);
Expand All @@ -44,7 +50,7 @@ class Card extends react.Component {
"div",
{
className: "main-card-draggable",
draggable: "true"
draggable: "false"
},
react.createElement(
"div",
Expand Down Expand Up @@ -104,6 +110,32 @@ class Card extends react.Component {
)
)
)
),
react.createElement(
Spicetify.ReactComponent.TooltipWrapper,
{ label: "Dismiss" },
react.createElement(
"button",
{
className: "main-card-closeButton",
onClick: this.closeButtonClicked.bind(this)
},
react.createElement(
"svg",
{
width: "18",
height: "18",
viewBox: "0 0 32 32",
xmlns: "http://www.w3.org/2000/svg",
className: "main-card-closeButton-svg"
},
react.createElement("path", {
d: "M31.098 29.794L16.955 15.65 31.097 1.51 29.683.093 15.54 14.237 1.4.094-.016 1.508 14.126 15.65-.016 29.795l1.414 1.414L15.54 17.065l14.144 14.143",
fill: "var(--spice-text)",
fillRule: "evenodd"
})
)
)
)
),
react.createElement(
Expand Down
25 changes: 24 additions & 1 deletion CustomApps/new-releases/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,30 @@ function openConfig() {
}
localStorage.setItem(`${APP_NAME}:${name}`, value);
}
})
}),
react.createElement(
"div",
{
className: "setting-row"
},
react.createElement(
"label",
{
className: "col description"
},
"Dismissed releases"
),
react.createElement(
"div",
{
className: "col action"
},
react.createElement(ButtonText, {
text: Spicetify.Locale.get("equalizer.reset"),
onClick: removeCards.bind(this, null, "reset")
})
)
)
);

Spicetify.PopupModal.display({
Expand Down
Loading