js+css实现人机对战中国象棋游戏代码

代码语言:html

所属分类:游戏

代码描述:js+css实现人机对战中国象棋游戏代码

代码标签: js css 人机 对战 中国 象棋 游戏 代码

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

		<!DOCTYPE html>
		<html lang="en">
			<head>
				<meta charset="UTF-8">
				<meta name="viewport" content="width=device-width, initial-scale=1.0">
				<style>
					body {
						background-color: white; /* Ensure the iframe has a white background */
					}
				</style>
				<script>
					var Z_CDN_WHITELIST = [
						'cdn.jsdelivr.net',
						'cdnjs.cloudflare.com',
						'cdn.tailwindcss.com',
						'unpkg.com',
						'fonts.googleapis.com',
						'd3js.org',
						'cdn.babylonjs.com',
						'html2canvas.hertzen.com',
						'code.jquery.com',
						'cdn.datatables.net',
						'kit.fontawesome.com',
						'code.createjs.com',
						'cdn.plot.ly',
						'fonts.gstatic.com',
						'www.rgraph.net',
						'api.mapbox.com',
						'polyfill.io',
						'cdn.quilljs.com',
						'picsum.photos',
						'esm.sh'
					];

					function z_isUrlInWhitelist(url) {
						if (!url || typeof url !== 'string') {
							return false;
						}
						try {
							const urlObj = new URL(url);
							const hostname = urlObj.hostname;
							return Z_CDN_WHITELIST.some(domain => hostname === domain);
						} catch (e) {
							return false;
						}
					}

						function z_proxyCdnUrl(url) {
						if (!url || !url.startsWith('http')) {
							return url;
						}
							if (!z_isUrlInWhitelist(url)) {
							return url;
						}
						if (!url.startsWith('https://artifacts-cdn.chatglm.site/')) {
							return 'https://artifacts-cdn.chatglm.site/' + url;
						}
						return url;
					}
					
					// 增强版外部链接拦截 - 适合放在模板字符串中
					document.addEventListener('click', function (ev) {
						try {
							const anchor = ev.target?.closest?.('a[href]') || null;
							if (!anchor) return;

							let href = anchor.getAttribute('href')?.trim() || '';
							if (!href) return;

							if (href.startsWith('javascript:')) return;

							// 新需求:href="#" 的链接完全阻止跳转和任何行为
							if (href === '#') {
								ev.preventDefault();
								return;
							}

							// 处理其他内部锚点(如 #about、#contact 等)
							if (href.startsWith('#')) {
								const rawId = href.slice(1);
								if (!rawId) return;

								const id = decodeURIComponent(rawId);
								const target = 
									document.getElementById(id) ||
									document.querySelector('a[name="' + id.replace(/"/g, '\"') + '"]') ||
									document.querySelector('[name="' + id.replace(/"/g, '\"') + '"]');

								if (target && target.scrollIntoView) {
									ev.preventDefault();
									try {
										history.pushState(null, '', href);
									} catch (e) {}
									target.scrollIntoView({ behavior: 'smooth', block: 'start' });
								}
								return;
							}

							// 处理外部链接
							let url;
							try {
								url = new URL(href, window.location.href);
							} catch (e) {
								return;
							}

							if (url.protocol !== 'http:' && url.protocol !== 'https:') return;

							const isExternal = url.hostname !== window.location.hostname;

							if (isExternal || anchor.getAttribute('target') === '_blank') {
								ev.preventDefault();
								window.open(url.toString(), '_blank', 'noopener,noreferrer');
							}

						} catch (e) {
							// 出错时不阻止默认行为
						}
					}, true);

					// 1. 暴力清除函数:从 DOM 层面抹除 onclick 属性
					var Z_removeInlineOnclick = function () {
						// 专门锁定 href="#" 且带有 onclick 的 a 标签
						const targetedLinks = document.querySelectorAll('a[href="#"][onclick]');
						for (let i = 0; i < targetedLinks.length; i++) {
							targetedLinks[i].removeAttribute('onclick');
							targetedLinks[i].onclick = null; // 确保 JS 层的赋值也被清理
						}
					};
					// 3. 动态监测:防止页面通过异步加载重新生成带 onclick 的元素
					var z_observer = new MutationObserver(function () {
						Z_removeInlineOnclick();
					});

					z_observer.observe(document.documentElement, {
						childList: true,
						subtree: true,
						attributes: true,
						attributeFilter: ['onclick']
					});

					// 4. 初始化执行一次
					Z_removeInlineOnclick();

					const Z_rawCreateElement = document.createElement;

					document.createElement = function (tagName, ...args) {
						const el = Z_rawCreateElement.call(this, tagName, ...args);

						if.........完整代码请登录后点击上方下载按钮下载查看

网友评论0