Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. javascript:(function(){
  2. const USE_LOCALSTORAGE = true; /* localStorageを使用するかどうか */
  3. const TEXTAREA_HEIGHT = '240px'; /* テキストエリアの高さ */
  4.  
  5. var video = document.querySelector('#movie_player > div.html5-video-container > video');
  6. var time = Math.floor(video.currentTime);
  7. var h = Math.floor(time / 3600);
  8. var m = Math.floor((time / 60) % 60);
  9. var s = time % 60;
  10. var formattedTime = (h > 0) ? h + ':' + zeroPadding(m) + ':' + zeroPadding(s) : zeroPadding(m) + ':' + zeroPadding(s);
  11. function zeroPadding(num){return (Array(2).join('0') + num).slice(-2);}
  12.  
  13. var textarea = document.getElementById('textarea');
  14. if(textarea){
  15. textarea.value += (textarea.value) ? '\n' + formattedTime + ' ' : formattedTime + ' ';
  16. }else{
  17. var style = document.createElement('style');
  18. style.innerHTML = 'ytd-watch-flexy {--bml--textarea--height: ' + TEXTAREA_HEIGHT + '} #textarea {box-sizing: border-box; width: 100%;height: calc(var(--bml--textarea--height) - 3px); border: none; background-color: var(--yt-live-chat-action-panel-background-color); color: var(--yt-live-chat-primary-text-color)} ytd-watch-flexy[flexy_][is-two-columns_]:not([js-panel-height_]) #textarea ~ #chat.ytd-watch-flexy:not([collapsed]).ytd-watch-flexy, ytd-watch-flexy[flexy_] #textarea ~ #chat.ytd-watch-flexy:not([collapsed]).ytd-watch-flexy {min-height: min(596px, calc(100vh - var(--ytd-watch-flexy-masthead-height) - 2 * 24px - (var(--bml--textarea--height) - 3px)));max-height: calc(100vh - var(--ytd-watch-flexy-masthead-height) - 2 * 24px - (var(--bml--textarea--height) - 3px));}';
  19. document.head.append(style);
  20.  
  21. textarea = document.createElement('textarea');
  22. var panels = document.getElementById('panels');
  23. var parent = panels.parentNode;
  24. textarea.id = 'textarea';
  25. if(USE_LOCALSTORAGE) {
  26. var savedText = '';
  27. var url = document.location.href;
  28. var result = url.match(/youtube\.com\/watch\?v=([a-zA-Z0-9_-]{11})/);
  29. var videoId = (result) ? result[1] : url;
  30. var lastVideoId = localStorage.getItem('lastVideoId');
  31. if(lastVideoId == videoId){
  32. savedText = localStorage.getItem('lastEdittedText');
  33. }else{
  34. localStorage.setItem('lastVideoId', videoId);
  35. }
  36. textarea.value = (savedText) ? savedText + '\n' + formattedTime + ' ' : formattedTime + ' ';
  37. }else {
  38. textarea.value = formattedTime + ' ';
  39. }
  40. parent.insertBefore(textarea, panels);
  41. }
  42. textarea.scrollTop = textarea.scrollHeight;
  43. if(USE_LOCALSTORAGE) {
  44. localStorage.setItem('lastEdittedText', textarea.value);
  45. }
  46. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement