MediaWiki:Common.js:修订间差异

MediaWiki界面页面
(更新BANNER)
(1)
标签已被回退
第79行: 第79行:
importScript(scriptToImport);
importScript(scriptToImport);
})();
})();
/* 2024 */
const gridContainer = document.querySelector('.grid');
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const columnCount = Math.floor(window.innerWidth / 50);
const rowCount = Math.floor(window.innerHeight / 50);
const cells = [];
// 生成字符网格
function createGrid() {
    for (let i = 0; i < rowCount; i++) {
        for (let j = 0; j < columnCount; j++) {
            const cell = document.createElement('div');
            cell.className = 'cell';
            // 随机选择字符并设置内容
            cell.textContent = characters.charAt(Math.floor(Math.random() * characters.length));
            gridContainer.appendChild(cell);
            cells.push(cell);
        }
    }
}
// 随机亮起字符
function activateRandomCells() {
    // 随机选择数量
    const count = Math.floor(Math.random() * 4) + 1;
    // 记录已激活的单元格索引
    const activatedIndices = new Set();
    for (let i = 0; i < count; i++) {
        let randomIndex;
        do {
            randomIndex = Math.floor(Math.random() * cells.length);
        } while (activatedIndices.has(randomIndex)); // 确保不重复选择同一个字符
        activatedIndices.add(randomIndex);
        const cell = cells[randomIndex];
        // 随机选择新的字符并更新内容
        cell.textContent = characters.charAt(Math.floor(Math.random() * characters.length));
        cell.classList.add('active');
        // 立即淡出
        setTimeout(() => {
            cell.classList.remove('active');
            cell.classList.add('fade');
        }, 300);
        // 及时移除 fade 类
        setTimeout(() => {
            cell.classList.remove('fade');
        }, 1300);
    }
}
// 每 142 毫秒执行一次
setInterval(activateRandomCells, 142);
// 初始化网格
createGrid();

2024年10月9日 (三) 01:57的版本

/* 这里的任何JavaScript将为所有用户在每次页面加载时加载。 */
function ModifySidebar( action, section, name, link ) {
	try {
		switch ( section ) {
			case 'languages':
				var target = 'p-lang';
				break;
			case 'toolbox':
				var target = 'p-tb';
				break;
			case 'navigation':
				var target = 'p-navigation';
				break;
			default:
				var target = 'p-' + section;
				break;
		}

		if ( action == 'add' ) {
			var node = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var aNode = document.createElement( 'a' );
			var liNode = document.createElement( 'li' );

			aNode.appendChild( document.createTextNode( name ) );
			aNode.setAttribute( 'href', link );
			liNode.appendChild( aNode );
			liNode.className = 'plainlinks';
			node.appendChild( liNode );
		}

		if ( action == 'remove' ) {
			var list = document.getElementById( target )
							   .getElementsByTagName( 'div' )[0]
							   .getElementsByTagName( 'ul' )[0];

			var listelements = list.getElementsByTagName( 'li' );

			for ( var i = 0; i < listelements.length; i++ ) {
				if (
					listelements[i].getElementsByTagName( 'a' )[0].innerHTML == name ||
					listelements[i].getElementsByTagName( 'a' )[0].href == link
				)
				{
					list.removeChild( listelements[i] );
				}
			}
		}


	} catch( e ) {
		// let's just ignore what's happened
		return;
	}
}

function CustomizeModificationsOfSidebar() {
	// adds [[Special:CategoryTree|Special:CategoryTree]] to toolbox
	// ModifySidebar( 'add', 'toolbox', 'CategoryTree', 'https://en.wikipedia.org/wiki/Special:CategoryTree' );
	// removes [[Special:Upload|Special:Upload]] from toolbox
	ModifySidebar( 'remove', 'toolbox', 'Upload file', '/index.php?title=%E7%89%B9%E6%AE%8A:%E7%89%B9%E6%AE%8A%E9%A1%B5%E9%9D%A2' );
}

jQuery( CustomizeModificationsOfSidebar );

(function() {
	const pageScripts = {
	    '首页': 'MediaWiki:Index.js',
        '琴叶茜·葵': 'MediaWiki:Index.js',
        '圣符传说': 'MediaWiki:Index.js',
        '圣符传说': 'MediaWiki:Index.js',
	    '飽きて放置したゲームの世界、からヤンデレヒロインがやってきて…': 'MediaWiki:Index.js'
	};
	const currentPageName = mw.config.get('wgPageName');
	const scriptToImport = pageScripts[currentPageName];
	if (scriptToImport)
		importScript(scriptToImport);
})();

/* 2024 */
const gridContainer = document.querySelector('.grid');
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
const columnCount = Math.floor(window.innerWidth / 50); 
const rowCount = Math.floor(window.innerHeight / 50); 
const cells = [];

// 生成字符网格
function createGrid() {
    for (let i = 0; i < rowCount; i++) {
        for (let j = 0; j < columnCount; j++) {
            const cell = document.createElement('div');
            cell.className = 'cell';
            // 随机选择字符并设置内容
            cell.textContent = characters.charAt(Math.floor(Math.random() * characters.length));
            gridContainer.appendChild(cell);
            cells.push(cell);
        }
    }
}

// 随机亮起字符
function activateRandomCells() {
    // 随机选择数量
    const count = Math.floor(Math.random() * 4) + 1;

    // 记录已激活的单元格索引
    const activatedIndices = new Set();

    for (let i = 0; i < count; i++) {
        let randomIndex;
        do {
            randomIndex = Math.floor(Math.random() * cells.length);
        } while (activatedIndices.has(randomIndex)); // 确保不重复选择同一个字符

        activatedIndices.add(randomIndex);
        const cell = cells[randomIndex];

        // 随机选择新的字符并更新内容
        cell.textContent = characters.charAt(Math.floor(Math.random() * characters.length));
        cell.classList.add('active');

        // 立即淡出
        setTimeout(() => {
            cell.classList.remove('active');
            cell.classList.add('fade');
        }, 300); 

        // 及时移除 fade 类
        setTimeout(() => {
            cell.classList.remove('fade');
        }, 1300); 
    }
}

// 每 142 毫秒执行一次
setInterval(activateRandomCells, 142); 

// 初始化网格
createGrid();