File tree 1 file changed +34
-0
lines changed
1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ //ドメインを設定(本番環境に合わせて書き換え)
2
+ const domain = 'https://hebimalu0000.github.io' ;
3
+ //現在のURLを取得
4
+ const url = location . href ;
5
+
6
+ //ページの読み込み終了時に実行
7
+ document . addEventListener ( "DOMContentLoaded" , function ( event ) {
8
+ //翻訳ページが表示されている場合
9
+ if ( url . match ( / _ x _ t r _ s c h / ) ) {
10
+
11
+ //ドメイン以降のパスを取得(パラメータ含まず)
12
+ const path = location . pathname ;
13
+
14
+ //リンク先が入っている要素を取得
15
+ const elm_ja = document . getElementById ( 'lang_ja' ) ;
16
+ const elm_en = document . getElementById ( 'lang_en' ) ;
17
+ const elm_es = document . getElementById ( 'lang_es' ) ;
18
+
19
+ //日本語・英語・スペイン語それぞれの翻訳先URLをセット(ドメインまで)
20
+ let ja_url = domain ;
21
+ let en_url = 'https://translate.google.com/translate?sl=ja&tl=en&u=' + domain ;
22
+ let es_url = 'https://translate.google.com/translate?sl=ja&tl=es&u=' + domain ;
23
+
24
+ //各URLに現在のパスを足してURLを完成させる
25
+ ja_url = ja_url + path ;
26
+ en_url = en_url + path ;
27
+ es_url = es_url + path ;
28
+
29
+ //optionタグのvalueを書き換え
30
+ elm_ja . setAttribute ( 'value' , ja_url ) ;
31
+ elm_en . setAttribute ( 'value' , en_url ) ;
32
+ elm_es . setAttribute ( 'value' , es_url ) ;
33
+ }
34
+ } ) ;
You can’t perform that action at this time.
0 commit comments