// ==UserScript== // @name Address List BGP Plus // @namespace https://github.com/AdroitAdorKhan/addrlistbgpPlus // @updateURL https://raw.githubusercontent.com/AdroitAdorKhan/addrlistbgpPlus/main/addrlistbgp.user.js // @downloadURL https://raw.githubusercontent.com/AdroitAdorKhan/addrlistbgpPlus/main/addrlistbgp.user.js // @version 1.2 // @description Get Address List from BGP and more. // @author Ador // @match https://bgp.he.net/search* // @match https://bgp.he.net/AS* // @grant none // @require https://code.jquery.com/jquery-3.6.0.min.js // ==/UserScript== (function() { 'use strict'; // Initial setup: add styles and HTML elements to the page $("#content").prepend(` `); let listname = ''; // Event listener for the dropdown list $("#listnameDropdown").change(function() { listname = $(this).val(); // Update listname variable with selected value $("#listname").val(listname); // Also update the input field to match the dropdown updateTableContent(); // Update table content immediately when dropdown value changes }); // Event listener for the input field $("#listname").on('input', function() { listname = $(this).val(); // Update listname variable with input field value updateTableContent(); // Update table content immediately when input field value changes }); // Event listener for the Refresh List Name button $("#refreshListName").click(function() { listname = $("#listname").val(); updateTableContent(); // Update table content immediately when the listname is refreshed }); // Append a link to trigger script generation //$("#header_search").append("Get Address List Script"); $("|Get Address List").appendTo("h1:has(a[rel='bookmark'])"); // Event listener for the Get Address List Script link $("#getscript").click(function() { updateTableContent(); $("#result").show(); // Ensure the result div is visible }); // Event listener for the Copy Script button $("#cpscript").click(function() { if (listname.trim() === '') { alert("Please enter a list name. List Name can't be empty!"); return; } copyTable(document.getElementById("tblresult")); }); // Event listener for the Close button $("#close").click(function() { $("#result").hide(); $("#tblresult").html(""); }); // Function to update the content of the table based on the current listname function updateTableContent() { $("#tblresult").html(""); // Clear previous content $("#tblresult").append("/ip firewall address-list"); var tr = $('table tr').filter(function() { return $(this).find("td"); }); tr.each(function() { var comment = ""; var ip = $(this).find('a').html(); if (location.href.split("/")[3].substr(0, 2) == "AS") { comment = $('#header').find('a')[1].innerHTML; } else { comment = $('#header').find('h1')[0].innerHTML.split('"')[1].split('"')[0]; } if (ip && ip.split(".").length == 4) { $("#tblresult").append(`add address=` + ip + ` list="` + listname + `" comment="` + comment + `"`); } }); $("#tblresult").append(""); } // Function to copy the content of the table to the clipboard function copyTable(el) { var body = document.body, range, sel; if (document.createRange && window.getSelection) { range = document.createRange(); sel = window.getSelection(); sel.removeAllRanges(); try { range.selectNodeContents(el); sel.addRange(range); } catch (e) { range.selectNode(el); sel.addRange(range); } } else if (body.createTextRange) { range = body.createTextRange(); range.moveToElementText(el); range.select(); } document.execCommand("copy"); } })();