如何使用JS

时间:2018-06-28 14:22:10

标签: javascript html

嗨,我想问一下如何用JS替换整个属性。我需要替换为:

<div class="content twitter-container twitter-tab active" id="panel2-3">
  <div id="ember1069" class="ember-view tse-scrollable">
    <div class="tse-scrollbar" style="display: block;">
      <div class="drag-handle" style="top: 2px; height: 81px;"></div>
    </div>
    <div class="tse-scroll-content" style="width: 374px; height: 836px;">
      <div class="tse-content">
        <div id="ember1087" class="ember-view"><!----></div>
      </div>
    </div>
  </div>
</div>

与此:

<div class="content twitter-container twitter-tab active" id="panel2-3" aria-hidden="false">
  <div id="ember1123" class="ember-view tse-scrollable">
    <div class="tse-scrollbar" style="display: none;">
      <div class="drag-handle" style="top: 2px; height: 81px;"></div>
    </div>
  <div class="tse-scroll-content" style="width: 374px; height: 836px;">
    <div class="chat">
      <iframe id="chat_embed" src="https://www.twitch.tv/embed/?????????/chat?darkpopout" scrolling="no" width="374" height="836" frameborder="0">&amp;amp;amp;amp;lt;br /&amp;amp;amp;amp;gt;
      </iframe>
    </div>
  </div>
</div>

我需要在网站中找到第一个脚本,并用第二个脚本进行更改。我尝试过这样的事情:

 (function() {
 'use strict';
const htmlString = `
<div class="content twitter-container twitter-tab active" id="panel2-3" aria-hidden="false">
 <div id="ember1123" class="ember-view tse-scrollable">
  <div class="tse-scrollbar" style="display: none;">
    <div class="drag-handle" style="top: 2px; height: 81px;"></div>
  </div>
 <div class="tse-scroll-content" style="width: 374px; height: 836px;">
  <div class="chat">
    <iframe id="chat_embed" src="https://www.twitch.tv/embed/?????????/chat?darkpopout" scrolling="no" width="374" height="836" frameborder="0">&amp;amp;amp;amp;lt;br /&amp;amp;amp;amp;gt;
    </iframe>
  </div>
 </div>
 </div>
 `;

document.querySelector('.parent').innerHTML = htmlString;
var myvar = '<div class="parent">'+
'  <div class="content twitter-container twitter-tab active" id="panel2-3">'+
'    <div id="ember1069" class="ember-view tse-scrollable">'+
'      <div class="tse-scrollbar" style="display: block;">'+
'        <div class="drag-handle" style="top: 2px; height: 81px;"></div>'+
'      </div>'+
'      <div class="tse-scroll-content" style="width: 374px; height: 836px;">'+
'        <div class="tse-content">'+
'          <div id="ember1087" class="ember-view"><!----></div>'+
'        </div>'+
'      </div>'+
'    </div>'+
'  </div>'+
'</div>';
})();

我不是要使用它的网站所有者。我想注入可以找到第一个HTML字符串并将其替换为我自己的HTML字符串的脚本。 (已经有可以将JS注入网站的插件,只需要代码方面的帮助即可。)

它是Tampermonkey Chrome / Mozilla扩展程序的用户脚本。

0 个答案:

没有答案