"Open in New Tab" Button

Open in New Tab button.

当前为 2023-11-20 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name "Open in New Tab" Button
  3. // @namespace Zero
  4. // @version 1.2.3
  5. // @description Open in New Tab button.
  6. // @author Who cares
  7. // @match *://*/*
  8. // @exclude *://about:blank/*
  9. // @grant none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. function addOpenInNewTabButton(link) {
  16. const button = document.createElement('button');
  17. button.style.position = 'absolute';
  18. button.style.zIndex = '9999';
  19. button.style.padding = '1px';
  20. button.style.background = 'white';
  21. button.style.color = 'black';
  22. button.style.border = '1px solid #555555';
  23. button.style.borderRadius = '5px'; // Kenarların oval olması için
  24. button.style.cursor = 'pointer';
  25. button.style.margin = '5px'; // Buton ile bağlantı arasında "?" piksel aralık
  26. button.style.opacity = '0.7'; // Saydamlık 💀
  27.  
  28. // İlk ikon
  29. const icon1 = document.createElement('img');
  30. icon1.src = 'https://i.ibb.co/b71mV9V/new-tab-dark.png'; // İkon URL
  31. icon1.style.width = '15px'; // İkonun genişliği ayarlanabilir
  32.  
  33. // İkinci ikon (mouseover durumunda görünecek)
  34. const icon2 = document.createElement('img');
  35. icon2.src = 'https://i.ibb.co/b71mV9V/new-tab-dark.png'; // İkinci ikonun URL'si
  36. icon2.style.width = '20px'; // İkinci ikonun genişliği
  37. icon2.style.display = 'none'; // İkinci ikonu başlangıçta gizle
  38.  
  39. button.appendChild(icon1);
  40. button.appendChild(icon2);
  41.  
  42. button.addEventListener('click', function(event) {
  43. event.stopPropagation();
  44. window.open(link.href, '_blank');
  45. });
  46.  
  47. // Bağlantının altına ekleniyor
  48. link.parentNode.appendChild(button);
  49.  
  50. // Hover olayları
  51. button.addEventListener('mouseover', function() {
  52. button.style.border = '1px solid #777777'; // Mouse üzerine gelindiğinde kenarlık rengi
  53. button.style.background = '#ffff00'; // Mouse üzerine gelindiğinde buton rengi
  54. button.style.color = 'white';
  55. icon1.style.display = 'none'; // İlk ikonu gizle
  56. icon2.style.display = 'inline'; // İkinci ikonu göster
  57. });
  58.  
  59. button.addEventListener('mouseout', function() {
  60. button.style.border = '1px solid #777777';
  61. button.style.background = 'white';
  62. button.style.color = 'black';
  63. icon1.style.display = 'inline'; // İlk ikonu göster
  64. icon2.style.display = 'none'; // İkinci ikonu gizle
  65. });
  66. }
  67.  
  68. // Sayfa içindeki tüm bağlantıların yanında butonu tutar
  69. document.querySelectorAll('a').forEach(function(link) {
  70. addOpenInNewTabButton(link);
  71. });
  72. })();