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