OneDrive Show long file name

長いファイル名をポップアップで表示

  1. // ==UserScript==
  2. // @name OneDrive Show long file name
  3. // @namespace http://github.com/segabito
  4. // @version 0.1.2
  5. // @description 長いファイル名をポップアップで表示
  6. // @author segabito
  7. // @match https://onedrive.live.com/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12.  
  13. var __css__ = (function() {/*
  14.  
  15. .FileNamePopup {
  16. position: fixed;
  17. top: 7px;
  18. left: 210px;
  19. background-color: #ffc;
  20. z-index: 1000;
  21. padding: 2px 24px;
  22. font-weight: bolder;
  23. border: solid 1px #888;
  24. border-radius: 8px;
  25. box-shadow: 2px 2px 4px #333;
  26. opacity: 0.8;
  27. pointer-events: none;
  28. }
  29.  
  30. .FileNamePopup:empty {
  31. display: none;
  32. }
  33.  
  34. .DetailsRow-cell.displayName:hover::after {
  35. content: attr(aria-label);
  36. position: fixed;
  37. top: 7px;
  38. left: 210px;
  39. background-color: #fff;
  40. z-index: 10000001;
  41. padding: 2px 24px;
  42. font-weight: bolder;
  43. border: solid 1px #888;
  44. border-radius: 8px;
  45. }
  46.  
  47.  
  48. */}).toString().match(/[^]*\/\*([^]*)\*\/\}$/)[1].replace(/\{\*/g, '/*').replace(/\*\}/g, '*/');
  49. var addStyle = function(styles, targetWindow) {
  50. if (!targetWindow) { targetWindow = self; }
  51. var elm = targetWindow.document.createElement('style');
  52. elm.type = 'text/css';
  53.  
  54. var text = styles.toString();
  55. text = targetWindow.document.createTextNode(text);
  56. elm.appendChild(text);
  57. var head = targetWindow.document.getElementsByTagName('head');
  58. head = head[0];
  59. head.appendChild(elm);
  60. return elm;
  61. };
  62.  
  63. var $popup;
  64. var adjustPopup = function(x, y) {
  65. //var offset = $popup.offset();
  66. var $window = $(window);
  67. var screenWidth = $window.innerWidth();
  68. var screenHeight = $window.innerHeight();
  69. var height = $popup.outerHeight();
  70. var top = Math.max(0, Math.min(y + 50, screenHeight - height));
  71. var width = $popup.outerWidth();
  72. var left = Math.max(0, Math.min(x - width / 3, screenWidth - width));
  73. //console.log('adjustPopup: %s, %s -> %s, %s', x, y, top, left);
  74. $popup.css({
  75. 'top': top,
  76. 'left': left
  77. });
  78. };
  79. var hidePopup = function() {
  80. $popup.text('');
  81. };
  82. var onListCellMouseover = function(e) {
  83. var $target = $(e.target).closest('.ItemTile');
  84. var $name = $target.find('.ItemTile-name');
  85. var name = $name.text();
  86. //console.log('%cfilename: %s', 'background: cyan; ', name);// $target[0], $name[0]);
  87. if (name) {
  88. $target.attr('title', name);
  89. $popup.text(name);
  90. adjustPopup(e.clientX, e.clientY);
  91. }
  92. };
  93.  
  94. var onDetailsRowMouseover = function(e) {
  95. var $target = $(e.target).closest('.DetailsRow');
  96. var $name = $target.find('.displayName');
  97. var name = $name.text();
  98. //console.log('%cfilename: %s', 'background: cyan; ', name, e);
  99. if (name) {
  100. $target.attr('title', name);
  101. $popup.text(name);
  102. adjustPopup(e.clientX, e.clientY);
  103. }
  104. };
  105. var onItemTileMouseover = function(e) {
  106. var $target = $(e.target).closest('.c-SetItemTile');
  107. var $name = $target.find('.titleArea');
  108. var name = $name.text();
  109. //console.log('%cfilename: %s', 'background: cyan; ', name, e);
  110. if (name) {
  111. $target.attr('title', name);
  112. $popup.text(name);
  113. adjustPopup(e.clientX, e.clientY);
  114. }
  115. };
  116. var initialize = function() {
  117. addStyle(__css__);
  118. $popup = $('<div class="FileNamePopup"></div>');
  119. $body = $('body');
  120. $body.append($popup);
  121. $body.on('mouseover', '.List-cell .ItemTile', onListCellMouseover);
  122. $body.on('mouseover', '.DetailsRow .displayName', onDetailsRowMouseover);
  123. $body.on('mouseover', '.child .c-SetItemTile', onItemTileMouseover);
  124. $body.on('mousedown', hidePopup);
  125. $('.od-SuiteNav').on('mouseover', hidePopup);
  126. };
  127.  
  128. var initTimer = window.setInterval(function() {
  129. if (window.$) {
  130. window.clearInterval(initTimer);
  131. window.setTimeout(initialize, 500);
  132. }
  133. }, 500);
  134. })();