Merge pull request #2417 from Phillweston/original-main-fix-DOMException

Fix dom exception problem
This commit is contained in:
tangly1024
2024-08-28 12:19:26 +08:00
committed by GitHub
20 changed files with 94 additions and 47 deletions

View File

@@ -28,16 +28,16 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v2
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
@@ -47,14 +47,14 @@ jobs:
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v3
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64

View File

@@ -24,11 +24,11 @@ jobs:
runs-on: ubuntu-latest # 运行环境为最新版的Ubuntu
steps:
- name: 'Checkout codes' # 步骤一,获取仓库代码
uses: actions/checkout@v2
uses: actions/checkout@v4
# - name: 'Run baiduPush' # 步骤二执行sh命令文件
# run: npm install && npm run baiduPush # 运行目录是仓库根目录
- name: Set up Python 3.8
uses: actions/setup-python@v1
uses: actions/setup-python@v5
with:
python-version: 3.8

View File

@@ -17,7 +17,7 @@ jobs:
steps:
# Step 1: run a standard checkout action
- name: Checkout target repo
uses: actions/checkout@v3
uses: actions/checkout@v4
# Step 2: run the sync action
- name: Sync upstream changes

View File

@@ -545,7 +545,7 @@ const BLOG = {
process.env.ENABLE_CACHE ||
process.env.npm_lifecycle_event === 'build' ||
process.env.npm_lifecycle_event === 'export', // 在打包过程中默认开启缓存,开发或运行时开启此功能意义不大。
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables) isProd: process.env.VERCEL_ENV === 'production' // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
isProd: process.env.VERCEL_ENV === 'production' || process.env.EXPORT, // distinguish between development and production environment (ref: https://vercel.com/docs/environment-variables#system-environment-variables)
BUNDLE_ANALYZER: process.env.ANALYZE === 'true' || false, // 是否展示编译依赖内容与大小
VERSION: process.env.NEXT_PUBLIC_VERSION // 版本号
}

View File

@@ -24,19 +24,19 @@ const Ackee = () => {
},
{
/*
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
* Enable or disable tracking of personal data.
* We recommend to ask the user for permission before turning this option on.
*/
detailed: true,
/*
* Enable or disable tracking when on localhost.
*/
* Enable or disable tracking when on localhost.
*/
ignoreLocalhost: false,
/*
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
* Enable or disable the tracking of your own visits.
* This is enabled by default, but should be turned off when using a wildcard Access-Control-Allow-Origin header.
* Some browsers strictly block third-party cookies. The option won't have an impact when this is the case.
*/
ignoreOwnVisits: false
}
)

View File

@@ -117,12 +117,14 @@ export default function CustomContextMenu(props) {
function handleCopy() {
const selectedText = document.getSelection().toString()
if (selectedText) {
const tempInput = document.createElement('input')
tempInput.value = selectedText
document.body.appendChild(tempInput)
tempInput.select()
document.execCommand('copy')
document.body.removeChild(tempInput)
const tempInput = document.createElement('input');
tempInput.value = selectedText;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand('copy');
if (tempInput && tempInput.parentNode && tempInput.parentNode.contains(tempInput)) {
tempInput.parentNode.removeChild(tempInput);
}
// alert("Text copied: " + selectedText);
} else {
// alert("Please select some text first.");

View File

@@ -24,7 +24,9 @@ export default function DifyChatbot() {
return () => {
// 在组件卸载时清理 script 标签
const existingScript = document.getElementById(siteConfig('DIFY_CHATBOT_TOKEN')); // 注意调用 siteConfig()
if (existingScript) document.body.removeChild(existingScript);
if (existingScript && existingScript.parentNode && existingScript.parentNode.contains(existingScript)) {
existingScript.parentNode.removeChild(existingScript);
}
};
}, []); // 注意依赖数组为空,意味着脚本将仅在加载页面时执行一次

View File

@@ -186,10 +186,19 @@ const ExternalPlugin = props => {
async
dangerouslySetInnerHTML={{
__html: `
(function(c,l,a,r,i,t,y){
c[a]=c[a]||function(){(c[a].q=c[a].q||[]).push(arguments)};
t=l.createElement(r);t.async=1;t.src="https://www.clarity.ms/tag/"+i;
y=l.getElementsByTagName(r)[0];y.parentNode.insertBefore(t,y);
(function(c, l, a, r, i, t, y) {
c[a] = c[a] || function() {
(c[a].q = c[a].q || []).push(arguments);
};
t = l.createElement(r);
t.async = 1;
t.src = "https://www.clarity.ms/tag/" + i;
y = l.getElementsByTagName(r)[0];
if (y && y.parentNode) {
y.parentNode.insertBefore(t, y);
} else {
l.head.appendChild(t);
}
})(window, document, "clarity", "script", "${CLARITY_ID}");
`
}}
@@ -204,8 +213,24 @@ const ExternalPlugin = props => {
async
dangerouslySetInnerHTML={{
__html: `
(function(i,s,o,g,r,a,m){i["DaoVoiceObject"]=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;a.charset="utf-8";m.parentNode.insertBefore(a,m)})(window,document,"script",('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/daf1a94b.js","daovoice")
`
(function(i, s, o, g, r, a, m) {
i["DaoVoiceObject"] = r;
i[r] = i[r] || function() {
(i[r].q = i[r].q || []).push(arguments);
};
i[r].l = 1 * new Date();
a = s.createElement(o);
m = s.getElementsByTagName(o)[0];
a.async = 1;
a.src = g;
a.charset = "utf-8";
if (m && m.parentNode) {
m.parentNode.insertBefore(a, m);
} else {
s.head.appendChild(a);
}
})(window, document, "script", ('https:' == document.location.protocol ? 'https:' : 'http:') + "//widget.daovoice.io/widget/daf1a94b.js", "daovoice")
`
}}
/>
<script

View File

@@ -116,7 +116,11 @@ class MessengerCustomerChat extends Component {
js = d.createElement(s);
js.id = id;
js.src = `https://connect.facebook.net/${language}/sdk/xfbml.customerchat.js`;
fjs.parentNode.insertBefore(js, fjs);
if (fjs && fjs.parentNode && fjs.parentNode.contains(fjs)) {
fjs.parentNode.insertBefore(js, fjs);
} else {
document.body.appendChild(js);
}
})(document, 'script', 'facebook-jssdk');
/* eslint-enable */
}

View File

@@ -34,7 +34,7 @@ export function PWA(post, siteInfo) {
// 删除已有的 manifest link 元素(如果存在)
const existingManifest = document.querySelector('link[rel="manifest"]')
if (existingManifest) {
if (existingManifest && existingManifest.parentNode && existingManifest.parentNode.contains(existingManifest)) {
existingManifest.parentNode.removeChild(existingManifest)
}

View File

@@ -74,7 +74,7 @@ const loadPrismThemeCSS = (isDarkMode, prismThemeSwitch, prismThemeDarkPath, pri
PRISM_PREVIOUS = prismThemeDarkPath
}
const previousTheme = document.querySelector(`link[href="${PRISM_PREVIOUS}"]`)
if (previousTheme) {
if (previousTheme && previousTheme.parentNode && previousTheme.parentNode.contains(previousTheme)) {
previousTheme.parentNode.removeChild(previousTheme)
}
loadExternalResource(PRISM_THEME, 'css')

View File

@@ -6,8 +6,8 @@ import { useEffect } from 'react';
*/
const useAdjustStyle = () => {
/**
* 避免 callout 含有图片时溢出撑开父容器
*/
* 避免 callout 含有图片时溢出撑开父容器
*/
const adjustCalloutImg = () => {
const callOuts = document.querySelectorAll('.notion-callout-text');
callOuts.forEach((callout) => {

View File

@@ -43,7 +43,10 @@ bszCaller = {
return function (t) {
ready(function () {
try {
e(t), scriptTag && scriptTag.parentElement && scriptTag.parentElement.removeChild && scriptTag.parentElement.removeChild(scriptTag)
e(t)
if (scriptTag && scriptTag.parentElement && scriptTag.parentElement.contains(scriptTag)) {
scriptTag.parentElement.removeChild(scriptTag)
}
} catch (t) {
// console.log(t), bszTag.hides()
}

View File

@@ -185,6 +185,10 @@ const nextConfig = {
'themes',
THEME
)
// Enable source maps in development mode
if (process.env.NODE_ENV_API === 'development') {
config.devtool = 'source-map'
}
return config
},
experimental: {
@@ -201,7 +205,6 @@ const nextConfig = {
},
publicRuntimeConfig: {
// 这里的配置既可以服务端获取到,也可以在浏览器端获取到
NODE_ENV_API: process.env.NODE_ENV_API || 'prod',
THEMES: themes
}
}

View File

@@ -3,7 +3,7 @@ const idFlutteringRibbon = 'canvasFlutteringRibbon'
function destroyFlutteringRibbon() {
const ribbon = document.getElementById(idFlutteringRibbon)
if (ribbon && ribbon.parentNode) {
if (ribbon && ribbon.parentNode && ribbon.parentNode.contains(ribbon)) {
ribbon.parentNode.removeChild(ribbon)
}
}

View File

@@ -109,7 +109,7 @@ function createNest() {
function destroyNest() {
const nest = document.getElementById(idNest)
if(nest && nest.parentNode){
if (nest && nest.parentNode && nest.parentNode.contains(nest)) {
nest.parentNode.removeChild(nest)
}
}

View File

@@ -80,7 +80,7 @@ function createRibbon() {
function destroyRibbon() {
const ribbon = document.getElementById(idRibbon)
if (ribbon && ribbon.parentNode) {
if (ribbon && ribbon.parentNode && ribbon.parentNode.contains(ribbon)) {
ribbon.parentNode.removeChild(ribbon)
}
}

View File

@@ -165,9 +165,11 @@ function createSakura() {
function stopp() {
if (staticx) {
var child = document.getElementById(id)
child.parentNode.removeChild(child)
window.cancelAnimationFrame(stop)
staticx = false
if (child && child.parentNode && child.parentNode.contains(child)) {
child.parentNode.removeChild(child)
window.cancelAnimationFrame(stop)
staticx = false
}
} else {
startSakura()
}
@@ -177,7 +179,7 @@ function createSakura() {
// 销毁樱花雨
function destroySakura() {
const sakura = document.getElementById(idSakura)
if (sakura && sakura.parentNode) {
if (sakura && sakura.parentNode && sakura.parentNode.contains(sakura)) {
sakura.parentNode.removeChild(sakura)
}
}

View File

@@ -258,7 +258,11 @@ const LayoutSlug = props => {
videoWrapper.appendChild(figCaptionWrapper)
}
// 放入页面
notionArticle.insertBefore(videoWrapper, notionArticle.firstChild)
if (notionArticle.firstChild && notionArticle.contains(notionArticle.firstChild)) {
notionArticle.insertBefore(videoWrapper, notionArticle.firstChild)
} else {
notionArticle.appendChild(videoWrapper)
}
}
}

View File

@@ -102,7 +102,9 @@ const checkThemeDOM = () => {
elements[elements.length - 1].scrollIntoView()
// 删除前面的元素,只保留最后一个元素
for (let i = 0; i < elements.length - 1; i++) {
elements[i].parentNode.removeChild(elements[i])
if (elements[i] && elements[i].parentNode && elements[i].parentNode.contains(elements[i])) {
elements[i].parentNode.removeChild(elements[i])
}
}
}
}