mirror of
				https://github.com/Mabbs/mabbs.github.io
				synced 2025-11-03 13:05:48 +00:00 
			
		
		
		
	Update 2 files
- /assets/js/main_new.js - /_layouts/post.html
This commit is contained in:
		
							parent
							
								
									00ed1a9b50
								
							
						
					
					
						commit
						d10e960a8d
					
				@ -102,7 +102,7 @@ $.get(BlogAPI + "/suggest?id={{ page.url }}&update=" + lastUpdated.valueOf(), fu
 | 
				
			|||||||
        var item = searchMap[data[j].id];
 | 
					        var item = searchMap[data[j].id];
 | 
				
			||||||
        if (item) {
 | 
					        if (item) {
 | 
				
			||||||
          var link = $('<a href="' + item.url + '">' + item.title + '</a>');
 | 
					          var link = $('<a href="' + item.url + '">' + item.title + '</a>');
 | 
				
			||||||
          var contentPreview = item.content.replace(/<[^>]+>/g, "").substring(0, 100);
 | 
					          var contentPreview = item.content.substring(0, 100);
 | 
				
			||||||
          if (item.content.length > 100) {
 | 
					          if (item.content.length > 100) {
 | 
				
			||||||
                contentPreview += "……";
 | 
					                contentPreview += "……";
 | 
				
			||||||
          }
 | 
					          }
 | 
				
			||||||
 | 
				
			|||||||
@ -44,30 +44,34 @@ $(function () {
 | 
				
			|||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$(function() {
 | 
					$(function() {
 | 
				
			||||||
    var codeBlocks = document.querySelectorAll('div.highlight');
 | 
					    var $codeBlocks = $('div.highlight');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    codeBlocks.forEach(function (codeBlock) {
 | 
					    $codeBlocks.each(function() {
 | 
				
			||||||
        var copyButton = document.createElement('button');
 | 
					        var $copyButton = $('<button>', {
 | 
				
			||||||
        copyButton.className = 'copy';
 | 
					            class: 'copy',
 | 
				
			||||||
        copyButton.type = 'button';
 | 
					            type: 'button',
 | 
				
			||||||
        copyButton.innerText = '📋';
 | 
					            text: '📋'
 | 
				
			||||||
 | 
					 | 
				
			||||||
        codeBlock.append(copyButton);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
        copyButton.addEventListener('click', function () {
 | 
					 | 
				
			||||||
            var code = codeBlock.querySelector('pre code').innerText.trim();
 | 
					 | 
				
			||||||
            window.navigator.clipboard.writeText(code)
 | 
					 | 
				
			||||||
                .then(() => {
 | 
					 | 
				
			||||||
                    copyButton.innerText = '✅';
 | 
					 | 
				
			||||||
                })
 | 
					 | 
				
			||||||
                .catch(err => {
 | 
					 | 
				
			||||||
                    copyButton.innerText = '❌';
 | 
					 | 
				
			||||||
                    console.error('Failed to copy:', err);
 | 
					 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $(this).append($copyButton);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $copyButton.on('click', function() {
 | 
				
			||||||
 | 
					            var code = $(this).siblings('pre').find('code').text().trim();
 | 
				
			||||||
 | 
					            var $button = $(this);
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            navigator.clipboard.writeText(code)
 | 
				
			||||||
 | 
					                .then(function() {
 | 
				
			||||||
 | 
					                    $button.text('✅');
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .catch(function(err) {
 | 
				
			||||||
 | 
					                    $button.text('❌');
 | 
				
			||||||
 | 
					                    console.error('复制失败:', err);
 | 
				
			||||||
 | 
					                })
 | 
				
			||||||
 | 
					                .finally(function() {
 | 
				
			||||||
                    setTimeout(function() {
 | 
					                    setTimeout(function() {
 | 
				
			||||||
                copyButton.innerText = '📋';
 | 
					                        $button.text('📋');
 | 
				
			||||||
                    }, 1500);
 | 
					                    }, 1500);
 | 
				
			||||||
                });
 | 
					                });
 | 
				
			||||||
        });
 | 
					        });
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user