Skip to content

Commit

Permalink
删除重复
Browse files Browse the repository at this point in the history
  • Loading branch information
webersongao committed Mar 8, 2024
1 parent 416e4e5 commit 53e57b8
Showing 1 changed file with 13 additions and 33 deletions.
46 changes: 13 additions & 33 deletions microblog/js/admin-scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,23 @@ Based on simple-microblogging plugin developed by Samuel Coskey, Victoria Gitman
*/

document.addEventListener('DOMContentLoaded', function () {
// Function to update links text and target
function updateLinksTextAndTarget(selector, searchText, newText, newTarget) {
var links = document.querySelectorAll(selector);
links.forEach(function (link) {
if (link.textContent && link.textContent.trim() === searchText) {
link.textContent = newText;
if (newTarget) {
link.setAttribute('target', newTarget);
}
}
});
// Function to update text content
function updateTextContent(selector, searchText, newText) {
var element = document.querySelector(selector);
if (element && element.textContent.trim() === searchText) {
element.textContent = newText;
}
}

// Update links and page title based on the current page URL
var currentPageURL = window.location.href;
if (currentPageURL.includes('post_type=micropost')) {
updateLinksTextAndTarget('a[href*="post_type=micropost"]', '写文章', '发微博');
updateLinksTextAndTarget('li#wp-admin-bar-archive a.ab-item', '查看文章', '微博列表', '_blank');
// Update search label
updateTextContent('.search-box label[for="post-search-input"]', '搜索文章:', '搜索微博:');

var pageTitle = document.title;
if (pageTitle && pageTitle.includes('写文章')) {
document.title = pageTitle.replace(/写文章/g, '发微博');
}
} else {
updateLinksTextAndTarget('a[href*="post_type=micropost"]', '写文章', '发微博');
// Update search button value
var searchButton = document.getElementById('search-submit');
if (searchButton && searchButton.value === '搜索文章') {
searchButton.value = '搜索微博';
}
});
/*
PluName: 微博 MicroBlog
PluLink: https://www.webersongao.com/tag/microblog
Desc: 将您的WordPress网站用作微博;在小部件中显示微博或使用短代码显示微博。
Author: WebersonGao
AuthorLink: https://www.webersongao.com
Based on simple-microblogging plugin developed by Samuel Coskey, Victoria Gitman(http://boolesrings.org),Thanks to obaby(https://h4ck.org.cn/) Thanks to ChatGPT.
*/

document.addEventListener('DOMContentLoaded', function () {

// Function to update links text and target
function updateLinksTextAndTarget(selector, searchText, newText, newTarget) {
var links = document.querySelectorAll(selector);
Expand Down

0 comments on commit 53e57b8

Please sign in to comment.