// ==UserScript== // @name 油管评论编辑 youtube 搬运烤肉man辅助 // @namespace http://tampermonkey.net/ // @version 0.1 // @description 可以直接修改youtube视频评论区 // @author manakanemu // @match *://www.youtube.com/watch?* // @grant none // @downloadURL none // ==/UserScript== (function() { (function (){ const css = document.createElement('style') css.innerHTML = '#expander{cursor: pointer;}' document.head.appendChild(css) })(); function bfFormat(words){ if(words === ''){ return '' }else{ return ''+words+'' } } function bbfFormat(words){ if(words === ''){ return '' }else{ return ''+words+'' } } function colorFormat(words,color){ if(words === ''){ return '' }else{ return ''+words+'' } } function basicFormat(words){ if(words === ''){ return '' }else{ return ''+words+'' } } function sizeFormat(words,size){ if(words === ''){ return '' }else{ return ''+words+'' } } function newlineFormat(words){ return words+'\n' } function parseBracketStart(string,index){ if(string[index] !== '{'){ return -1 }else{ let count = 1 for(let i = index+1;i -1 && t < times){ const keyword = string.substring(index).match(key)[group] const start = index + keyword.length-1 const end = parseBracketStart(string,start) pairs.push([index,start,end]) const newIndex = string.substring(index+1).search(key) if(newIndex > -1){ index += newIndex+1 }else{ index = newIndex } t += 1 } return pairs } function parseBF(string){ let pair = parseKey(string,/\\bf{/) while(pair.length > 0){ string = string.substring(0,pair[0][0]) + bfFormat(string.substring(pair[0][1]+1,pair[0][2])) + string.substring(pair[0][2]+1) pair = parseKey(string,/\\bf{/) } return string } function parseBbf(string){ let pair = parseKey(string,/\\bbf{/) while(pair.length > 0){ string = string.substring(0,pair[0][0]) + bbfFormat(string.substring(pair[0][1]+1,pair[0][2])) + string.substring(pair[0][2]+1) pair = parseKey(string,/\\bbf{/) } return string } function parseColor(string){ let pair = parseKey(string,/\\color\{.*?\}\{/) while(pair.length > 0){ const color = string.substring(pair[0][0],pair[0][1]).match(/\{(.*?)\}/)[1] string = string.substring(0,pair[0][0]) + colorFormat(string.substring(pair[0][1]+1,pair[0][2]),color) + string.substring(pair[0][2]+1) pair = parseKey(string,/\\color\{.*?\}\{/) } return string } function parseSize(string){ let pair = parseKey(string,/\\size\{.*?\}\{/) while(pair.length > 0){ const size = string.substring(pair[0][0],pair[0][1]).match(/\{(.*?)\}/)[1] string = string.substring(0,pair[0][0]) + sizeFormat(string.substring(pair[0][1]+1,pair[0][2]),size) + string.substring(pair[0][2]+1) pair = parseKey(string,/\\size\{.*?\}\{/) } return string } function parseNormal(string){ return basicFormat(string) } function parseComments(string,newline=true){ let html = parseBF(string) html = parseBbf(html) html = parseColor(html) html = parseSize(html) // html = parseNormal(html) if(newline){ return newlineFormat(html) }else{ return html } } function commentClick(){ const container = this.getElementsByTagName('yt-formatted-string')[1] let strings = '' if(container.children.length == 0){ strings += container.innerText }else{ const raw = container.innerHTML strings = raw strings = strings.replace(/\n<\/span>/g,'\n') while(strings.search(/(.*?)<\/span-color>/) > -1){ strings = strings.replace(/(.*?)<\/span-color>/g,'\\color{$1}{$2}') } while(strings.search(/(.*?)<\/span-size>/) > -1){ strings = strings.replace(/(.*?)<\/span-size>/g,'\\size{$1}{$2}') } while(strings.search(/(.*?)<\/span>/) > -1){ strings = strings.replace(/(.*?)<\/span>/g,'$1') } while(strings.search(/(.*?)<\/span-bold>/) > -1){ strings = strings.replace(/(.*?)<\/span-bold>/g,'\\bf{$1}') } while(strings.search(/(.*?)<\/strong>/) > -1){ strings = strings.replace(/(.*?)<\/strong>/g,'\\bbf{$1}') } while(strings.search(/(.*?)<\/span>/) > -1){ strings = strings.replace(/(.*?)<\/span>/g,'\\bf{$1}') } } const textarea = document.createElement('textarea') textarea.id = 'my-comment-textarea' textarea.value = strings textarea.style.position = 'absolute' textarea.style.height = '200px' textarea.style.width = this.offsetWidth + 'px' textarea.style.top = this.offsetTop+'px' textarea.style.left = this.offsetLeft+'px' document.body.appendChild(textarea) this.style.height = textarea.offsetHeight+'px' textarea.focus() textarea.onblur = function(){ const contents = this.value.split('\n') this.parentElement.removeChild(this) container.parentElement.parentElement.style.height = '' let htmls = '' for(let i=0;i