-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinkCard_Editor_5.2
1677 lines (1360 loc) · 68.9 KB
/
LinkCard_Editor_5.2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name LinkCard Editor ⭐
// @namespace http://tampermonkey.net/
// @version 5.2
// @description 通常表示でリンクカードを編集 「Ctrl+F6」
// @author personwritep
// @match https://blog.ameba.jp/ucs/entry/srventry*
// @exclude https://blog.ameba.jp/ucs/entry/srventrylist.do*
// @grant none
// ==/UserScript==
let mode=0; // ツールのON/OFF
let mode_e=0; // テキスト編集モード(enhance)
let mode_c=0; // サブコントロール
let retry=0;
let interval=setInterval(wait_target, 100);
function wait_target(){
retry++;
if(retry>10){
clearInterval(interval); }
let target=document.querySelector('#cke_1_contents');
if(target){
clearInterval(interval);
main(); }}
function main(){
let editor_iframe;
let iframe_doc;
let iframe_body;
let selection;
let range;
let ua=0;
let agent=window.navigator.userAgent.toLowerCase();
if(agent.indexOf('firefox')!=-1){ ua=1; } // Firefoxの場合
if(agent.indexOf('edg')!=-1){ ua=2; } // Edgeの場合
let read_json=localStorage.getItem('LinkCard Style');
let lcard_set=JSON.parse(read_json);
if(!Array.isArray(lcard_set)){
lcard_set=
[0, 0, "white", 1, "#e2e2e2", 0, "#333", "red", "", "", 4, 0, 0]; }
if(lcard_set.length<13){
lcard_set[11]=0;
lcard_set[12]=0; }
let write_json=JSON.stringify(lcard_set);
localStorage.setItem('LinkCard Style', write_json);
let target0=document.querySelector('#cke_1_contents');
let monitor0=new MutationObserver( catch_key );
monitor0.observe(target0, {childList: true});
catch_key();
function catch_key(){
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){
iframe_doc=editor_iframe.contentWindow.document;
if(iframe_doc){
when_back();
iframe_doc.addEventListener('keydown', check_key);
document.addEventListener('keydown', check_key);
function check_key(event){
if(event.ctrlKey && event.keyCode==117){
event.preventDefault();
event.stopImmediatePropagation();
if(mode==0 && editor_iframe){
mode=1;
sign();
card_edit(); }
else if(mode==1 && editor_iframe){
mode=0;
mode_e=0;
mode_c=0;
sign_clear();
card_close(); }}
if(event.keyCode==116){
event.preventDefault();
event.stopImmediatePropagation();
alert(
" ⛔ F5 / Ctrl + F5 / Shift + F5 \n"+
" このショートカットは現在のページを遷移して、編集中の\n"+
" データを損失する可能性があるので、無効にしています。\n"+
" ----- LinkCard Editor -----"); }}}}
before_end();
} // catch_key()
function when_back(){
if(mode==1){
sign();
card_close();
mode_e=0;
mode_c=0;
card_edit(); }}
function card_close(){
iframe_body=iframe_doc.querySelector('body');
if(iframe_body){
selection=iframe_doc.getSelection();
selection.removeAllRanges();
let target_card=iframe_body.querySelectorAll('.ogpCard_root');
for(let k=0; k<target_card.length; k++){
if(target_card[k].classList.contains('edit_card')){
target_card[k].classList.remove('edit_card');
if(target_card[k].classList.contains('edit_card_e')){
target_card[k].classList.remove('edit_card_e');
edit_span_end(target_card[k]); }}}
sens_help(0); }}
function card_edit(){
iframe_doc.onclick=function(event){
let elem=iframe_doc.elementFromPoint(event.clientX, event.clientY);
if(elem){
let select_card=elem.closest('.ogpCard_root');
if(select_card){
set_card(select_card, event); }}} // Card編集開始
function set_card(card, event){
event.preventDefault();
event.stopImmediatePropagation();
if(mode==1 && card.classList.contains('edit_card')){ // 対象カードでの操作
if(mode_e==0 &&
area_match(card, event) && (event.ctrlKey || event.shiftKey)){ // 編集選択
mode_e=1;
sens_help(2);
mode_enhance(card, event); }
else if(mode_e==1){
if(!area_match(card, event)){ // 編集終了
mode_e=0;
sens_help(1);
mode_no_enhance(card); }
else{
if(area_match(card, event).style.zIndex!='1'){
if(event.ctrlKey || event.shiftKey){ // 編集移動
edit_span_end(card);
selection.removeAllRanges();
mode_e=1;
sens_help(2);
mode_enhance(card, event); }
else { // 編集終了
mode_e=0;
sens_help(1);
mode_no_enhance(card); }}}}}
else if(mode==1 &&
!card.classList.contains('edit_card') && event.ctrlKey){ // 対象カード移動
mode_e=0;
mode_c=1;
card_close(); // 他のCardを閉じる
card.classList.add('edit_card');
sens_help(1);
url_reset();
edit_in(card); }}
} // card_edit()
function sens_help(n){
let e_hint=document.querySelector('#disp_le .e_hint');
if(e_hint){
if(n==0){
e_hint.innerHTML=''; }
if(n==1){
e_hint.innerHTML=
' テキスト編集:Ctrl+Click'; }
if(n==2){
e_hint.innerHTML=
' テキスト編集終了:Ctrl+Click テキストを全選択:Shift+Click'+
' '; }}}
function area_match(card, event){ // カード上のクリック場所の判定
let elem=iframe_doc.elementFromPoint(event.clientX, event.clientY);
let select_parent;
if(elem.textContent){
if(elem.closest('.ogpCard_title')){
select_parent=card.querySelector('.ogpCard_title'); }
if(elem.closest('.ogpCard_description')){
select_parent=card.querySelector('.ogpCard_description'); }
if(elem.closest('.ogpCard_urlText')){
select_parent=card.querySelector('.ogpCard_urlText'); }}
return select_parent; }
function mode_enhance(card, event){ // TEXT編集する
let target=area_match(card, event);
if(event.ctrlKey){
edit_span(target, 0); } // 対象SPANを編集 💢
else if(event.shiftKey){
edit_span(target, 1); } // 対象SPANを選択 💢
if(!card.classList.contains('edit_card_e')){
card.classList.add('edit_card_e'); }
let link=card.querySelector('.ogpCard_link');
if(link){
link.setAttribute('draggable', 'false'); }} // firefoxで必要
function mode_no_enhance(card){
if(card.classList.contains('edit_card_e')){
card.classList.remove('edit_card_e'); }
let link=card.querySelector('.ogpCard_link');
if(link.hasAttribute('draggable')){
link.removeAttribute('draggable'); } // firefoxで必要
edit_span_end(card); // 編集不能に戻す
selection.removeAllRanges(); }
function edit_span(elem, n){
elem.setAttribute('contenteditable', 'true');
elem.style.zIndex='1';
elem.style.outline='2px solid #2196f3';
elem.style.outlineOffset='3px';
elem.addEventListener('keydown', (e)=>{
if(e.ctrlKey && e.keyCode=='86'){
if(ua==1){
e.preventDefault();
e.stopImmediatePropagation();
alert("カードテキストに貼付け操作はできません"); }
else{
if(!e.shiftKey){
e.preventDefault();
e.stopImmediatePropagation();
alert("「Ctrl+Shift+V」で貼付けてください"); }}}});
if(n==1){
selection=iframe_doc.getSelection();
range=iframe_doc.createRange();
range.selectNodeContents(elem);
selection.removeAllRanges();
selection.addRange(range); }}
function edit_span_end(card){
let spans=card.querySelectorAll('span');
for(let k=0; k<spans.length; k++){
if(spans[k].hasAttribute('contenteditable')){
last_br(spans[k]);
spans[k].removeAttribute('contenteditable');
spans[k].style.zIndex='';
spans[k].style.outline='';
spans[k].style.outlineOffset=''; }}
function last_br(elem){
let elem_nodes=elem.childNodes;
for(let k=elem_nodes.length-1; k>=0; k--){
if(elem_nodes[k].nodeName=='BR'){
if(elem_nodes[k]==elem.lastChild){
elem_nodes[k].remove(); }}
else if(elem_nodes[k].nodeName!='#text'){
if(elem_nodes[k].nodeName!='SPAN' &&
elem_nodes[k].nodeName!='IMG'){
elem_nodes[k].outerHTML=elem_nodes[k].textContent; }}}}}
function edit_in(card){
if(mode==1){
if(!card.style.textAlign){
card.style.textAlign='center'; } // デフォルトで中央配置
let title=card.querySelector('.ogpCard_title');
let description=card.querySelector('.ogpCard_description');
if(title && !description){
let descrip=
'<span class="ogpCard_description" style="overflow: hidden; '+
'margin: 1px 0 0; font: 13px/1.4 Meiryo; text-align: left;"> '+
'</span>';
title.insertAdjacentHTML('afterend', descrip); } // 本文引用が無い場合に補填
let link=card.querySelector('.ogpCard_link');
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(!imageWrap){
let imgw=
'<span class="ogpCard_imageWrap" '+
'style="position:relative; width: 116px; height: 116px; flex-shrink:0; '+
'border: 1px solid #eee; overflow: hidden;"></span>';
link.insertAdjacentHTML('beforeend', imgw); } // カバー画像が無い場合にエリア確保
slim_title(card);
slim_icon(card);
item_setter(card);
align_in(card);
size_in(card);
bg_color(card);
tx_color(card);
set_url(card);
query_cut(card);
bd_color(card);
bd_width(card);
bd_radius(card);
svg_icon(card);
mem_plus(card);
mem_paste(card);
moz(card);
}} // edit_in()
function slim_title(card){ // 先頭・末尾の『』を削除
if(card.classList.contains('edit_card')){
let link=card.querySelector('.ogpCard_link');
if(link.getAttribute('href').includes('https://ameblo.jp/')){
let title=card.querySelector('.ogpCard_title');
if(title){
let title_str=title.innerHTML;
if(title_str.slice(0, 1)=='『' && title_str.slice(-1)=='』'){
title_str=title_str.slice(1).slice(0, -1); }
title.innerHTML=title_str; }}}}
function slim_icon(card){ // リンクマークをテキスト化
let url=card.querySelector('.ogpCard_url');
if(url){
url.style.margin='auto 0 0 20px'; }
let iconWrap=card.querySelector('.ogpCard_iconWrap');
if(iconWrap){
if(iconWrap.style.fill && iconWrap.style.fill !='currentcolor'){
iconWrap.style.color=iconWrap.style.fill; }
if(iconWrap.style.fill){
iconWrap.style.fill=''; }
if(card.querySelector('.ogpCard_icon') || card.querySelector('svg')){
iconWrap.innerHTML='∽';
iconWrap.style.position='';
iconWrap.style.width='16px';
iconWrap.style.height='14px';
iconWrap.style.flexShrink='';
iconWrap.style.font='bold 14px/17px Meiryo';
iconWrap.style.transform='rotate(135deg)'; }}
let urlText=card.querySelector('.ogpCard_urlText');
if(urlText){
urlText.style.fontSize='13px'; }}
function item_setter(card){
let target_i=document.querySelector('#js-photos-imageList');
let monitor_i=new MutationObserver(item_select);
monitor_i.observe(target_i, {childList: true, subtree: true}); // 画像パレット監視
item_select();
function item_select(){
let item=document.querySelectorAll('.p-images-imageList__item');
for(let k=0; k<item.length; k++){
item[k].addEventListener('click', function(event){
set_img(event, item[k]); }); }}
function set_img(e, item){
if(mode==1){
e.stopImmediatePropagation();
let img_src=item.getAttribute('data-image');
let inner=
'<img alt="" class="ogpCard_image" data-ogp-card-image="" '+
'height="120" loading="lazy" data-cke-saved-src="' + img_src +
'" src="' + img_src +
'" style="position:absolute;top:50%;left:50%;object-fit:cover;'+
'min-height:100%;min-width:100%;'+
'transform:translate(-50%,-50%)" width="120">';
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){
let target_card=iframe_body.querySelectorAll('.ogpCard_root');
for(let k=0; k<target_card.length; k++){
if(target_card[k].classList.contains('edit_card')){
range_con(target_card[k]);
let card_imgw=
target_card[k].querySelector('.ogpCard_imageWrap');
if(card_imgw){
card_imgw.innerHTML=inner; }}}
function range_con(card){
if(mode==1){
selection=iframe_doc.getSelection();
range=iframe_doc.createRange();
range.setStart(card, 0);
range.setEnd(card, 0);
selection.removeAllRanges();
selection.addRange(range); }}
}}} // set_img()
item_sign(card);
function item_sign(card){
let photos_w=document.querySelector('#js-photos-wrapper');
photos_w.addEventListener('mouseover', function(){
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap && card.classList.contains('edit_card')){
imageWrap.style.filter='invert(1)';
imageWrap.style.background='#442814'; }});
photos_w.addEventListener('mouseout', function(){
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap && card.classList.contains('edit_card')){
imageWrap.style.filter='';
imageWrap.style.background=''; }}); }
} // item_setter()
function align_in(card){
let al=document.querySelector('#disp_le .al');
let ac=document.querySelector('#disp_le .ac');
let ar=document.querySelector('#disp_le .ar');
al.onclick=function(){
if(card.style.textAlign!='left'){
if(card.classList.contains('edit_card')){
card.style.textAlign='left'; }}}
ac.onclick=function(){
if(card.classList.contains('edit_card')){
if(card.style.textAlign!='center'){
card.style.textAlign='center'; }}}
ar.onclick=function(){
if(card.classList.contains('edit_card')){
if(card.style.textAlign!='right'){
card.style.textAlign='right'; }}}
} // arrange_in()
function size_in(card){
let lz=document.querySelector('#disp_le .lz');
lz.onclick=function(event){
let link=card.querySelector('.ogpCard_link');
if(card.classList.contains('edit_card')){
if(event.ctrlKey){
ex_compact(card); }
else{
if(mode_e==1){
mode_e=0;
mode_no_enhance(card); }
else{
if(link){
if(link.style.height=='108px'){
arrange_min(card); }
else if(link.style.height=='auto'){
arrange_default(card); }
else{ // 未アレンジは compactに変更
arrange_compact(card); }}}}}}
} // size_in()
function ex_compact(card){
let ok=confirm(
" 💢 リンクカードの小型最軽量化オプション\n\n"+
" 「OK」 を押すと 「カバー画像」「記事の本文部」 を削除します。\n"+
" 軽量化を元に戻すには、カードを最初から作り直してください。");
if(ok){
if(card.classList.contains('edit_card')){
arrange_ex_compact(card); }
mode_e=0; // テキスト編集モードのリセット
mode_no_enhance(card); }
else{ ; }} // ex_compact()
function arrange_ex_compact(card){
let link=card.querySelector('.ogpCard_link');
if(link){
link.style.width='500px';
link.style.height='';
link.style.margin='';
link.style.boxSizing=''; }
let content=card.querySelector('.ogpCard_content');
if(content){
content.style.padding='7px 15px 4px 15px';
content.style.flexDirection='';
content.style.overflow='';
content.style.justifyContent='inherit'; }
let title=card.querySelector('.ogpCard_title');
if(title){
title.style.WebkitBoxOrient='';
title.style.display='';
title.style.WebkitLineClamp='';
title.style.maxHeight='19px';
title.style.flexShrink='';
title.style.font='bold 16px/1.25 Meiryo'; }
let description=card.querySelector('.ogpCard_description');
if(description){
description.remove(); }
let url=card.querySelector('.ogpCard_url');
if(url){
url.style.margin=''; }
let urlText=card.querySelector('.ogpCard_urlText');
if(urlText){
urlText.style.overflow='';
urlText.style.textOverflow='';
urlText.style.textAlign=''; }
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap){
imageWrap.remove(); }
let ogpCard_wrap=card.querySelector('.ogpCard_wrap');
if(ogpCard_wrap){
ogpCard_wrap.removeAttribute('contenteditable'); }
if(link){
link.removeAttribute('data-ogp-card-log');
link.removeAttribute('data-cke-saved-href');
let fake=document.createElement("img");
if(!link.querySelector('img')){
link.appendChild(fake); }}
let all_obj=card.querySelectorAll('*');
for(let k=0; k<all_obj.length; k++){
all_obj[k].classList.remove(
'ogpCard_wrap', 'ogpCard_content', 'ogpCard_title',
'ogpCard_url', 'ogpCard_iconWrap', 'ogpCard_urlText'); }
card.classList.remove('ogpCard_root', 'edit_card');
let dupe=card.cloneNode(true);
card.parentNode.replaceChild(dupe, card); }
function arrange_compact(card){
let link=card.querySelector('.ogpCard_link');
if(link){
link.style.width='500px';
link.style.height='108px';
link.style.margin='0 auto';
link.style.boxSizing=''; }
let content=card.querySelector('.ogpCard_content');
if(content){
content.style.padding='8px 25px 4px 15px';
content.style.flexDirection='column';
content.style.justifyContent='inherit'; }
let title=card.querySelector('.ogpCard_title');
if(title){
title.style.maxHeight='39px';
title.style.flexShrink='0';
title.style.font='bold 16px/1.25 Meiryo';
title.style.WebkitLineClamp='2'; }
let description=card.querySelector('.ogpCard_description');
if(description){
description.style.whiteSpace='';
description.style.textOverflow='';
description.style.margin='0';
description.style.font='13px/1.4 Meiryo';
description.style.display=''; }
let url=card.querySelector('.ogpCard_url');
if(url){
url.style.margin='auto 0 0 20px'; }
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap){
imageWrap.style.width='98px';
imageWrap.style.height='98px';
imageWrap.style.margin='auto 0';
imageWrap.style.top='';
imageWrap.style.right='15px';
imageWrap.style.border='1px solid #eee';
imageWrap.style.overflow='hidden';
imageWrap.style.display=''; }}
function arrange_min(card){
let link=card.querySelector('.ogpCard_link');
if(link){
link.style.width='500px';
link.style.height='auto';
link.style.margin='0 auto';
link.style.boxSizing=''; }
let content=card.querySelector('.ogpCard_content');
if(content){
content.style.padding='7px 15px 4px 15px';
content.style.flexDirection='row';
content.style.justifyContent='inherit'; }
let title=card.querySelector('.ogpCard_title');
if(title){
title.style.maxHeight='19px';
title.style.flexShrink='1';
title.style.font='bold 16px/1.25 Meiryo';
title.style.WebkitLineClamp='1'; }
let description=card.querySelector('.ogpCard_description');
if(description){
description.style.whiteSpace='';
description.style.textOverflow='';
description.style.margin='0';
description.style.font='13px/1.4 Meiryo';
description.style.display='none'; }
let url=card.querySelector('.ogpCard_url');
if(url){
url.style.margin='0'; }
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap){
imageWrap.style.width='';
imageWrap.style.height='';
imageWrap.style.margin='';
imageWrap.style.top='';
imageWrap.style.right='';
imageWrap.style.border='';
imageWrap.style.overflow='';
imageWrap.style.display='none'; }}
function arrange_default(card){
let link=card.querySelector('.ogpCard_link');
if(link){
link.style.width='620px';
link.style.height='120px';
link.style.margin='';
link.style.boxSizing='border-box'; }
let content=card.querySelector('.ogpCard_content');
if(content){
content.style.padding='12px 16px 8px';
content.style.flexDirection='column';
content.style.justifyContent='inherit';
content.style.backgroundColor=''; }
let title=card.querySelector('.ogpCard_title');
if(title){
title.style.maxHeight='44px';
title.style.flexShrink='0';
title.style.font='bold 16px/1.25 Meiryo';
title.style.WebkitLineClamp='2'; }
let description=card.querySelector('.ogpCard_description');
if(description){
description.style.whiteSpace='';
description.style.textOverflow='';
description.style.marginTop='1px';
description.style.font='13px/1.4 Meiryo';
description.style.display=''; }
let url=card.querySelector('.ogpCard_url');
if(url){
url.style.margin='auto 0 0 20px'; }
let imageWrap=card.querySelector('.ogpCard_imageWrap');
if(imageWrap){
imageWrap.style.width='120px';
imageWrap.style.height='120px';
imageWrap.style.margin='';
imageWrap.style.top='';
imageWrap.style.right='';
imageWrap.style.border='';
imageWrap.style.overflow='hidden';
imageWrap.style.display=''; }}
function bg_color(card){
let set_color;
let lc_color=document.querySelector('#lc_color');
let lc_trance=document.querySelector('#lc_trance');
let link=card.querySelector('.ogpCard_link');
let link_bgc=link.style.backgroundColor;
if(link_bgc){
lc_color.style.backgroundColor=link_bgc;
lc_trance.value=rgba_trance(link_bgc);
set_color=link_bgc; }
import_color(card, lc_color, link, 'bg');
let target_elem=lc_color;
let monitor_elem=new MutationObserver(import_c);
monitor_elem.observe(target_elem, {attributes: true});
function import_c(){
if(target_elem.style.opacity==2){
monitor_elem.disconnect();
setTimeout(()=>{
lc_trance.value=1;
set_color=lc_color.style.backgroundColor;
target_elem.style.opacity=1;
}, 40);
monitor_elem.observe(target_elem, {attributes: true}); }}
lc_trance.addEventListener('input', function(event){
event.preventDefault();
let set_color_tmp=rgba(set_color, lc_trance.value);
let lc_color=document.querySelector('#lc_color');
lc_color.style.backgroundColor=set_color_tmp;
let link=card.querySelector('.ogpCard_link');
if(card.classList.contains('edit_card')){
link.style.backgroundColor=set_color_tmp; }});
function rgba(c_val, alpha){ // 透過色の白背景時の非透過色に変換
let R, G, B;
let c_val_arr=c_val.split(',');
if(c_val_arr.length==3){
R=c_val_arr[0].replace(/[^0-9]/g, '');
G=c_val_arr[1].replace(/[^0-9]/g, '');
B=c_val_arr[2].replace(/[^0-9]/g, '');
return 'rgb('+cpColor(R, alpha)+', '+cpColor(G, alpha)+', '+cpColor(B, alpha)+')'
function cpColor(deci_code, alp){
const colorCode=deci_code*alp + 255*(1 - alp);
return Math.floor(colorCode).toString(10); }}
else{
return c_val; }}
} // bg_color()
function import_color(card, sw, target, type){
let color_label;
let icon_button;
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
iframe_doc=editor_iframe.contentWindow.document;
selection=iframe_doc.getSelection();
if(ua==0 || ua==2){
color_label=document.querySelector('#cke_16_label');
icon_button=document.querySelector('#cke_17'); }
else if(ua==1){
color_label=document.querySelector('#cke_15_label');
icon_button=document.querySelector('#cke_16'); }
let target_p=color_label;
let monitor_p=new MutationObserver(get_copy);
sw.onclick=function(event){
if(card.classList.contains('edit_card')){
selection.removeAllRanges(); // 記事中の選択に誤指定を防止
icon_button.click();
monitor_p.observe(target_p, {attributes: true}); }}
function get_copy(){
if(card.classList.contains('edit_card')){
if(type=='bg'){
sw.style.backgroundColor=color_label.style.backgroundColor;
target.style.backgroundColor=sw.style.backgroundColor;
sw.style.opacity=2; }
if(type=='cl'){
sw.style.backgroundColor=color_label.style.backgroundColor;
target.style.color=sw.style.backgroundColor;
let iconWrap=card.querySelector('.ogpCard_iconWrap');
if(iconWrap){
iconWrap.style.color=''; }
let svg=document.querySelector('#link_mark');
if(svg){
svg.style.color=sw.style.backgroundColor; }}
if(type=='bd'){
sw.style.backgroundColor=color_label.style.backgroundColor;
target.style.borderColor=sw.style.backgroundColor; }
if(type=='svg'){
sw.style.color=color_label.style.backgroundColor;
target.style.color=sw.style.color; }}
monitor_p.disconnect(); }
document.addEventListener('mousedown', function(){
monitor_p.disconnect(); });
if(document.querySelector('.cke_wysiwyg_frame')!=null){
editor_iframe=document.querySelector('.cke_wysiwyg_frame');
if(editor_iframe){
iframe_doc=editor_iframe.contentWindow.document;
if(iframe_doc){
iframe_doc.addEventListener('mousedown', function(){
monitor_p.disconnect(); }); }}}
let target_body=document.querySelector('.l-body');
let monitor_generator=new MutationObserver(stealth);
monitor_generator.observe(target_body, {childList: true, subtree: true});
function stealth(){
let color_generator=document.querySelector('.ck-l-colorGenerator');
if(color_generator){
color_generator.addEventListener('mousedown', function(event){
event.stopImmediatePropagation(); }); }}
} // import_color()
function rgba_trance(color_val){
let trance_val;
let c_val_arr=color_val.split(',');
if(c_val_arr.length!=4){
trance_val=1; }
else{
trance_val=c_val_arr[3].replace(/[^0-9]/g, '')/10; }
return trance_val; }
function bg_reset(){
let lc_color=document.querySelector('#lc_color');
let lc_trance=document.querySelector('#lc_trance');
lc_color.style.background='#fff';
lc_trance.value=1; }
function tx_color(card){ // Cardの基本文字色指定
let link=card.querySelector('.ogpCard_link');
if(link.style.color==''){ // 配色がある場合は訂正しない
link.style.color='rgb(51, 51, 51)'; } // Cardの基本文字色を指定
let title=card.querySelector('.ogpCard_title');
if(title){
title.style.color=''; }
let description=card.querySelector('.ogpCard_description');
if(description){
description.style.color=''; }
let urlText=card.querySelector('.ogpCard_urlText');
if(urlText){
urlText.style.color=''; }
let tc_color=document.querySelector('#tc_color');
tc_color.style.background=link.style.color;
import_color(card, tc_color, link, 'cl');
} // tx_color()
function tx_reset(){
let tc_color=document.querySelector('#tc_color');
tc_color.style.background='#fff'; }
function set_url(card){
let url_wide=document.querySelector('#url_wide');
let url_input=document.querySelector('#url_input');
let url_clear=document.querySelector('#ex_disp .url_clear');
let lw_h=document.querySelector('#lw_h');
let write_url=document.querySelector('#write_url');
url_input.onclick=function(){
if(mode_c==1){
if(!url_input.classList.contains('url_input_w')){
url_input.classList.add('url_input_w');
lw_h.classList.remove('lw_hint');
lw_h.classList.add('lw_hint_w');
url_wide.style.display='block'; }}}
url_wide.onclick=function(event){
event.stopImmediatePropagation();
if(mode_c==1){
if(url_input.classList.contains('url_input_w')){
url_input.classList.remove('url_input_w');
lw_h.classList.remove('lw_hint_w');
lw_h.classList.add('lw_hint');
url_wide.style.display='none'; }}}
let link=card.querySelector('.ogpCard_link');
let def_url=link.getAttribute('href');
url_input.value=def_url;
url_clear.onclick=function(event){
event.stopImmediatePropagation();
url_input.value=''; }
write_url.onclick=function(event){
let urlText=card.querySelector('.ogpCard_urlText');
if(event.shiftKey){
if(card.classList.contains('edit_card')){
if(urlText){
if(urlText.textContent==get_domain(card)){
urlText.textContent=def_url; } // cardのURLを記入
else{
urlText.textContent=get_domain(card); }}}} // ドメイン表示
else{
rewrite(); }}
url_input.onkeydown=function(event){
if(event.keyCode==13){
event.stopImmediatePropagation();
event.preventDefault();
rewrite(); }}
function rewrite(){
def_url=link.getAttribute('href');
if(url_input.value!='' && url_input.value!=def_url){ // 変更ある場合のみ実行
let ok=confirm(
" 💢 リンクカードのURL書換えオプション\n\n"+
" 現在の「URL入力枠」の内容をリンクURLに設定します。\n"+
" ➔ カードを右クリックしてリンクを新しいウインドウに開く\n"+
" ことで、カードに設定されたリンクURLを確認出来ます。");
if(ok){
if(card.classList.contains('edit_card')){
link.setAttribute('href', url_input.value);
let data_cke_saved_href=
link.getAttribute('data-cke-saved-href');
if(data_cke_saved_href){
link.setAttribute('data-cke-saved-href', url_input.value); }
url_input.style.background='#80deea';
setTimeout(()=>{
url_input.style.background='';
}, 500); }}
else{
url_input.style.background='#80deea';
url_input.value='現在のリンクURLに戻します';
setTimeout(()=>{
url_input.style.background='';
url_input.value=def_url; // URL入力枠内容を元に戻す
}, 3000); }}
else{
url_input.value=def_url;
if(url_input.classList.contains('url_input_w')){
url_input.classList.remove('url_input_w');
lw_h.classList.remove('lw_hint_w');
lw_h.classList.add('lw_hint');
url_wide.style.display='none'; }}}
function get_domain(card){
let domain=def_url.match(/^https?:\/{2,}(.*?)(?:\/|\?|#|$)/)[1];
return domain; }
} // set_url()
function query_cut(card){
let link=card.querySelector('.ogpCard_link');
let url_input=document.querySelector('#url_input');
let am_url=document.querySelector('#am_url');
if(am_url){
am_url.onclick=function(){
let def_url=link.getAttribute('href');
let smart_url;
let product;
if(def_url.indexOf('www.amazon.co')==-1){ // Amazon以外
smart_url=cut_after(def_url, '?'); }
else{ // Amazonの場合
if(def_url.indexOf('/b/')==-1 && def_url.indexOf('/b?')==-1 &&
def_url.indexOf('/s/')==-1 && def_url.indexOf('/s?')==-1 &&
cut_before(def_url, '?').indexOf('node=')==-1){
if(def_url.indexOf('/gp/')!=-1){
product=cut_after(cut_before(cut_after(def_url, '?'), '/gp/'), '/ref=');
smart_url='https://www.amazon.co.jp'+ product; }
else if(def_url.indexOf('/dp/')!=-1){
product=cut_after(cut_before(cut_after(def_url, '?'), '/dp/'), '/ref=');
smart_url='https://www.amazon.co.jp'+ product; }
else{
smart_url=cut_after(def_url, '?'); }}
else{
smart_url=def_url; }}
if(card.classList.contains('edit_card')){
link.setAttribute('href', smart_url);
let data_cke_saved_href=
link.getAttribute('data-cke-saved-href');
if(data_cke_saved_href){
link.setAttribute('data-cke-saved-href', smart_url); }