<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
	<link rel="self" href="http://forum.script-coding.com/extern.php?action=feed&amp;tid=16011&amp;type=atom" />
	<updated>2021-01-24T11:57:29Z</updated>
	<generator>PunBB</generator>
	<id>http://forum.script-coding.com/viewtopic.php?id=16011</id>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145391#p145391" />
			<content type="html"><![CDATA[<p><strong>Malcev</strong>, ну, разных мнений может быть много. С моей точки зрения читается нормально, выглядит компактно.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-24T11:57:29Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145391#p145391</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145386#p145386" />
			<content type="html"><![CDATA[<p><a href="https://habr.com/ru/post/141746/">https://habr.com/ru/post/141746/</a></p>]]></content>
			<author>
				<name><![CDATA[Malcev]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=26930</uri>
			</author>
			<updated>2021-01-24T11:48:15Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145386#p145386</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145379#p145379" />
			<content type="html"><![CDATA[<p>А разве это запрещено? <em>(elem = item)</em> в контексте условного оператора возвращает <em>true</em>.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-24T06:00:38Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145379#p145379</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145378#p145378" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong>, а что, в условиях можно делать присваивания?</p><p>Вы в условиях делаете присваивания переменным?</p>]]></content>
			<author>
				<name><![CDATA[Cytrus]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=40205</uri>
			</author>
			<updated>2021-01-24T04:15:43Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145378#p145378</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145377#p145377" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Большое спасибо!!! Всё протестировал - всё работает!</p>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-24T03:16:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145377#p145377</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145376#p145376" />
			<content type="html"><![CDATA[<p>Это сколько раз будет запускаться таймер, если количество элементов с селектором <em>a#thumbnail</em> на странице после последнего скролла не изменилось. Такое может быть, если новые элементы слишком долго загружаются.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-24T00:27:33Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145376#p145376</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145375#p145375" />
			<content type="html"><![CDATA[<p><strong>teadrinker</strong><br />Можно ещё вопрос, за что отвечает параметр “counter == 5” в данной строке?<br /></p><div class="codebox"><pre><code> if ( (channel = searchCannel(channelName)) || counter == 5 ) {</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-24T00:21:18Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145375#p145375</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145374#p145374" />
			<content type="html"><![CDATA[<p>Да, опечатка, но в данном случае ни на что не влияет, можете исправить в обоих местах.</p>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-24T00:16:41Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145374#p145374</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145373#p145373" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-24T00:13:21Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145373#p145373</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145372#p145372" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[teadrinker]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=24515</uri>
			</author>
			<updated>2021-01-24T00:06:02Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145372#p145372</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145371#p145371" />
			<content type="html"><![CDATA[<p><strong>Cytrus</strong><br />Благодарю, подправил. Только странно, что поиск по слову работал и с ошибкой и без, исправление ни на что не повлияло. А как правильно добавить скроллинг сюда я до сих пор не пойму... Не подскажите?</p>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-23T23:42:40Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145371#p145371</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145370#p145370" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Cytrus]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=40205</uri>
			</author>
			<updated>2021-01-23T23:14:33Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145370#p145370</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145366#p145366" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-23T20:46:34Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145366#p145366</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145365#p145365" />
			<content type="html"><![CDATA[<p><strong>Michael</strong>, а если такого текста в принципе нет на странице?</p>]]></content>
			<author>
				<name><![CDATA[alexii]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=1844</uri>
			</author>
			<updated>2021-01-23T20:39:59Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145365#p145365</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: JS: Добавить автоскролл страницы, пока не найдет текст]]></title>
			<link rel="alternate" href="http://forum.script-coding.com/viewtopic.php?pid=145363#p145363" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Michael]]></name>
				<uri>http://forum.script-coding.com/profile.php?id=41356</uri>
			</author>
			<updated>2021-01-23T20:17:51Z</updated>
			<id>http://forum.script-coding.com/viewtopic.php?pid=145363#p145363</id>
		</entry>
</feed>
