<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Серый форум &mdash; JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
		<link>http://forum.script-coding.com/viewtopic.php?id=16011</link>
		<atom:link href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=16011&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[Недавние сообщения в теме «JS: Добавить автоскролл страницы, пока не найдет текст».]]></description>
		<lastBuildDate>Sun, 24 Jan 2021 11:57:29 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145391#p145391</link>
			<description><![CDATA[<p><strong>Malcev</strong>, ну, разных мнений может быть много. С моей точки зрения читается нормально, выглядит компактно.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 24 Jan 2021 11:57:29 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145391#p145391</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145386#p145386</link>
			<description><![CDATA[<p><a href="https://habr.com/ru/post/141746/">https://habr.com/ru/post/141746/</a></p>]]></description>
			<author><![CDATA[null@example.com (Malcev)]]></author>
			<pubDate>Sun, 24 Jan 2021 11:48:15 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145386#p145386</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145379#p145379</link>
			<description><![CDATA[<p>А разве это запрещено? <em>(elem = item)</em> в контексте условного оператора возвращает <em>true</em>.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 24 Jan 2021 06:00:38 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145379#p145379</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145378#p145378</link>
			<description><![CDATA[<p><strong>teadrinker</strong>, а что, в условиях можно делать присваивания?</p><p>Вы в условиях делаете присваивания переменным?</p>]]></description>
			<author><![CDATA[null@example.com (Cytrus)]]></author>
			<pubDate>Sun, 24 Jan 2021 04:15:43 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145378#p145378</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145377#p145377</link>
			<description><![CDATA[<p><strong>teadrinker</strong><br />Большое спасибо!!! Всё протестировал - всё работает!</p>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sun, 24 Jan 2021 03:16:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145377#p145377</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145376#p145376</link>
			<description><![CDATA[<p>Это сколько раз будет запускаться таймер, если количество элементов с селектором <em>a#thumbnail</em> на странице после последнего скролла не изменилось. Такое может быть, если новые элементы слишком долго загружаются.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 24 Jan 2021 00:27:33 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145376#p145376</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145375#p145375</link>
			<description><![CDATA[<p><strong>teadrinker</strong><br />Можно ещё вопрос, за что отвечает параметр “counter == 5” в данной строке?<br /></p><div class="codebox"><pre><code> if ( (channel = searchCannel(channelName)) || counter == 5 ) {</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sun, 24 Jan 2021 00:21:18 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145375#p145375</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145374#p145374</link>
			<description><![CDATA[<p>Да, опечатка, но в данном случае ни на что не влияет, можете исправить в обоих местах.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 24 Jan 2021 00:16:41 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145374#p145374</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145373#p145373</link>
			<description><![CDATA[<p>Благодарю за код, чуть позже протестирую, с телефона сейчас.</p><p>В строке: function searchCannel(channelName) {<br />searchCannel не должен быть searchC<strong>H</strong>annel?</p><p>И тут тоже:<br /></p><div class="codebox"><pre><code> if ( (channel = searchCannel(channelName)) || counter == 5 ) {</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sun, 24 Jan 2021 00:13:21 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145373#p145373</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145372#p145372</link>
			<description><![CDATA[<p><strong>Cytrus</strong>, уверены, что там ошибка? Этот код я писал, если что. <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /><br />Смотрите здесь: <a href="https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Operators/Operator_Precedence">Приоритет операторов</a><br /><strong>Michael</strong><br />Попробуйте так:<br /></p><div class="codebox"><pre><code>((channelName) =&gt; {
   function searchChannel(channelName) {
      const coll = document.querySelectorAll(&#039;div#channel-info&#039;);
      let elem = &#039;&#039;;
      for (let item of coll) {
         if ( item.innerText == channelName &amp;&amp; (elem = item) )
            break;
      }
      return elem;
   }
   let channel = &#039;&#039;, allElemsCount = 0, counter = 0;
   let timerId = setInterval(() =&gt; {
      if ( (channel = searchChannel(channelName)) || counter == 5 ) {
         clearInterval(timerId);
         if (channel)
            channel.parentNode.parentNode.querySelector(&#039;a#thumbnail&#039;).click();
         else
            alert(&#039;Not found!&#039;);
      }
      else {
         let newAllElemsCount = document.querySelectorAll(&#039;a#thumbnail&#039;).length;
         if (!(newAllElemsCount &gt; allElemsCount))
            counter++;
         else {
            allElemsCount = newAllElemsCount;
            window.scrollTo(0, document.querySelector(&#039;ytd-app&#039;).scrollHeight);
         }
      }
   }, 2000);
})(&#039;ИМЯ КАНАЛА&#039;);</code></pre></div><p>Имя канала в самом конце вставляйте.</p>]]></description>
			<author><![CDATA[null@example.com (teadrinker)]]></author>
			<pubDate>Sun, 24 Jan 2021 00:06:02 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145372#p145372</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145371#p145371</link>
			<description><![CDATA[<p><strong>Cytrus</strong><br />Благодарю, подправил. Только странно, что поиск по слову работал и с ошибкой и без, исправление ни на что не повлияло. А как правильно добавить скроллинг сюда я до сих пор не пойму... Не подскажите?</p>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sat, 23 Jan 2021 23:42:40 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145371#p145371</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145370#p145370</link>
			<description><![CDATA[<p>С первого взгляда видно, что ошибка. Что это такое?<br /></p><div class="codebox"><pre><code>if ( item.innerText == &#039;Skibyxa&#039; &amp;&amp; (elem = item) )</code></pre></div><p>Может быть так?<br /></p><div class="codebox"><pre><code>if ( (item.innerText == &#039;Skibyxa&#039;) &amp;&amp; (elem == item) )</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Cytrus)]]></author>
			<pubDate>Sat, 23 Jan 2021 23:14:33 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145370#p145370</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145366#p145366</link>
			<description><![CDATA[<p><strong>alexii</strong><br />В моем случае он рано или поздно будет, ибо ключевой запрос в поиске Ютуба задается мной в ручную.</p><p>И да, сейчас проверил, моё &quot;творение&quot; не работает опять... <br />Я понимаю что нужно сделать, но не понимаю как...<br />Мне надо зациклить выполнение этого:<br /></p><div class="codebox"><pre><code>   setTimeout(function () {
      window.scrollBy(0,5500);
   }, 1000);   </code></pre></div><p>пока не найдется элемент по которому кликнуть:<br /></p><div class="codebox"><pre><code> elem.parentNode.parentNode.querySelector(&#039;a#thumbnail&#039;).click();</code></pre></div><p><img src="//forum.script-coding.com/img/smilies/sad.png" width="15" height="15" /><br />Пробовал еще так (после этого страница тупо виснет):<br /></p><div class="codebox"><pre><code>(() =&gt; {
   const coll = document.querySelectorAll(&#039;div#channel-info&#039;);
   let elem;
   for (let item of coll) {
      if ( item.innerText == &#039;Skibyxa&#039; &amp;&amp; (elem = item) )
         break;
   };
   if (elem)
      elem.parentNode.parentNode.querySelector(&#039;a#thumbnail&#039;).click();
   else
      while (true) {
      window.scrollBy(0,5500);
      };
})();</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sat, 23 Jan 2021 20:46:34 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145366#p145366</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145365#p145365</link>
			<description><![CDATA[<p><strong>Michael</strong>, а если такого текста в принципе нет на странице?</p>]]></description>
			<author><![CDATA[null@example.com (alexii)]]></author>
			<pubDate>Sat, 23 Jan 2021 20:39:59 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145365#p145365</guid>
		</item>
		<item>
			<title><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link>http://forum.script-coding.com/viewtopic.php?pid=145363#p145363</link>
			<description><![CDATA[<p><strong>Update.</strong> Удалось добавить скролл в JS.<br />Теперь спроллит до упора, пока не найдет нужное значение.<br />Если кому нужно:<br /></p><div class="codebox"><pre><code>(() =&gt; {
   const coll = document.querySelectorAll(&#039;div#channel-info&#039;);
   let elem;
   for (let item of coll) {
      if ( item.innerText == &#039;НАЗВАНИЕ КАНАЛА&#039; &amp;&amp; (elem = item) )
         break;
   };
   if (elem)
      elem.parentNode.parentNode.querySelector(&#039;a#thumbnail&#039;).click();
   else
   setTimeout(function () {
      window.scrollBy(0,5500);
   }, 1000);   
})();</code></pre></div><p>Может не самый &quot;правильный&quot; способ, но работает на ура! <img src="//forum.script-coding.com/img/smilies/smile.png" width="15" height="15" /></p>]]></description>
			<author><![CDATA[null@example.com (Michael)]]></author>
			<pubDate>Sat, 23 Jan 2021 20:17:51 +0000</pubDate>
			<guid>http://forum.script-coding.com/viewtopic.php?pid=145363#p145363</guid>
		</item>
	</channel>
</rss>
