跳转到内容
主菜单
主菜单
移至侧栏
隐藏
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
ubuntustudioCN
搜索
搜索
外观
登录
个人工具
登录
查看“︁MediaWiki:Randownload.js”︁的源代码
系统消息
讨论
English
阅读
查看源代码
查看历史
工具
工具
移至侧栏
隐藏
操作
阅读
查看源代码
查看历史
常规
链入页面
相关更改
页面信息
外观
移至侧栏
隐藏
←
MediaWiki:Randownload.js
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
此页面为本wiki上的软件提供界面文本,并受到保护以防止滥用。如欲修改所有wiki的翻译,请访问
translatewiki.net
上的MediaWiki本地化项目。
您无权编辑此JavaScript页面,因为编辑此页面可能会影响所有访问者。
您可以查看和复制此页面的源代码。
// The function to download a single random link (remains the same) function downloadRandomLink(links) { if (!links || links.length === 0) { console.error("The provided links array is empty or invalid."); return; } const randomIndex = Math.floor(Math.random() * links.length); const randomLink = links[randomIndex]; const linkElement = document.createElement('a'); linkElement.href = randomLink; linkElement.download = `random_download_${Date.now()}`; // Example filename document.body.appendChild(linkElement); linkElement.click(); setTimeout(() => { document.body.removeChild(linkElement); }, 100); } document.addEventListener('DOMContentLoaded', () => { // Select all divs that are designated as random link generators const linkGeneratorDivs = document.querySelectorAll('.random-link-generator'); console.log("aaaaaa"); linkGeneratorDivs.forEach(containerDiv => { // Select all anchor (<a>) tags *within this specific div* const linkElements = containerDiv.querySelectorAll('a'); const extractedLinks = []; linkElements.forEach(link => { if (link.href) { extractedLinks.push(link.href); } }); if (extractedLinks.length > 0) { console.log("Found links in div:", extractedLinks); // Create a button for this specific div's link list const downloadButton = document.createElement('button'); downloadButton.textContent = 'Download Random Link from this block'; downloadButton.style.marginLeft = '10px'; // Add some spacing // Add an event listener to the button downloadButton.onclick = () => { downloadRandomLink(extractedLinks); }; // Append the button to the DOM. // We'll append it after the div for better placement. // If the div contains other elements you want the button after, // you might need a more specific insertion point. containerDiv.parentNode.insertBefore(downloadButton, containerDiv.nextSibling); } else { console.log("No links found within a .random-link-generator div."); } }); });
返回
MediaWiki:Randownload.js
。
搜索
搜索
查看“︁MediaWiki:Randownload.js”︁的源代码
添加话题