osu! select code block

Highlights Code Blocks

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

You will need to install an extension such as Tampermonkey to install this script.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        osu! select code block
// @namespace   s4nji
// @description Highlights Code Blocks
// @include     https://osu.ppy.sh/forum/*
// @version     1
// @grant       none
// ==/UserScript==

/*\
 * Creates a selection around the node
\*/

window.onload = function() {

  // Select Node | Credits to Álvaro G. Vicario- http://stackoverflow.com/a/4012861
  function selectNode(myNode){
      // Create a range
      try{ // FF
          var myRange = document.createRange();
      }catch(e){
          try{ // IE
              var myRange = document.body.createTextRange();
          }catch(e){
              return;
          }
      }

      // Asign text to range
      try{ // FF
          myRange.selectNode(myNode);
      }catch(e){
          try{ // IE
              myRange.moveToElementText(myNode);
          }catch(e){
              return;
          }
      }

      // Select the range
      try{ // FF
          var mySelection = window.getSelection();
          mySelection.removeAllRanges(); // Undo current selection
          mySelection.addRange(myRange);
      }catch(e){
          try{ // IE
              myRange.select();
          }catch(e){
              return;
          }
      }
  }

  // Add select code links/buttons next to code titles
  var el = " <a href='#' class='select-code'>[Select Code]</a>";
  jQuery('.codetitle').append(el);

  // Select Code Block near clicked select code links/buttons
  jQuery('.select-code').click( function(e) {
      e.preventDefault();
      selectNode( jQuery(this).parent().next()[0] );
  });

};