"Open Link in New Tab" Button

Adds an "Open link in new tab" button

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

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