<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Серый форум &mdash; VBScript: сохранить выделенный в Internet Explorer текст в файл]]></title>
	<link rel="self" href="https://forum.script-coding.com/extern.php?action=feed&amp;tid=1080&amp;type=atom" />
	<updated>2008-01-24T20:28:23Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.script-coding.com/viewtopic.php?id=1080</id>
		<entry>
			<title type="html"><![CDATA[VBScript: сохранить выделенный в Internet Explorer текст в файл]]></title>
			<link rel="alternate" href="https://forum.script-coding.com/viewtopic.php?pid=8295#p8295" />
			<content type="html"><![CDATA[<p>Скрипт для быстрого сохранения выделенного на HTML-странице текста в файл, добавляет в контекстное меню Internet Explorer команду &quot;Сохранить выделенный текст в файл&quot;. Что-то типа копилки: выделенный текст сохраняется в C:\Documents and Settings\***\Рабочий стол\SaveIESelectedText.txt путём дописывания этого файла. Перед каждым фрагментом вставляется секция заголовка с указанием даты, URL, заголовка страницы и запрашиваемого в момент сохранения комментария.<br /><strong>C:\Program Files\SaveIESelectedText\SaveIESelectedText.htm</strong><br /></p><div class="codebox"><pre><code>&lt;HTML&gt;
    &lt;HEAD&gt;
        &lt;TITLE&gt;Save IE selected text&lt;/TITLE&gt;
        &lt;SCRIPT language=&quot;VBScript&quot;&gt;
            Const strBaseRegKey = &quot;HKEY_CURRENT_USER\Software\SaveIESelectedText\&quot;
            
            Dim objWshShell
            Dim objFSO
            Dim objTS
            
            Dim strURL
            Dim strTitle
            Dim strSelectedText
            
            Dim strLastURL
            Dim boolUseDescription
            Dim strPath
            
            Dim strDescription
            
            With window.external.menuArguments.document
                strURL          = .URL
                strTitle        = .Title
                strSelectedText = Trim(.selection.createRange().text)
            End With
            
            If Len(strSelectedText) &lt;&gt; 0 Then
                Set objWshShell = CreateObject(&quot;WScript.Shell&quot;)
                
                On Error Resume Next
                
                strLastURL = objWshShell.RegRead(strBaseRegKey &amp; &quot;LastURL&quot;)
                
                If Err.Number &lt;&gt; 0 Then
                    Err.Clear
                    strLastURL = &quot;&quot;
                End If
                
                boolUseDescription = CBool(objWshShell.RegRead(strBaseRegKey &amp; &quot;UseDescription&quot;))
                
                If Err.Number &lt;&gt; 0 Then
                    Err.Clear
                    boolUseDescription = True
                End If
                
                Set objFSO = CreateObject(&quot;Scripting.FileSystemObject&quot;)
                strPath = objWshShell.ExpandEnvironmentStrings(objWshShell.RegRead(strBaseRegKey &amp; &quot;Path&quot;))
                
                If Err.Number &lt;&gt; 0 Then
                    Err.Clear
                    strPath = objFSO.BuildPath(objWshShell.SpecialFolders(&quot;Desktop&quot;), &quot;SaveIESelectedText.txt&quot;)
                End If
                
                On Error Goto 0
                
                Set objTS = objFSO.OpenTextFile(strPath, 8, True)
                
                With objTS
                    If strURL &lt;&gt; strLastURL Then
                        .WriteLine
                        .WriteLine String(79, &quot;=&quot;)
                        .WriteLine vbTab &amp; Now()
                        .WriteLine vbTab &amp; strURL
                        .WriteLine vbTab &amp; strTitle
                        
                        objWshShell.RegWrite strBaseRegKey &amp; &quot;LastURL&quot;, strURL, &quot;REG_SZ&quot;
                        
                        If boolUseDescription Then
                            strDescription = window.prompt(&quot;Введите описание:&quot;, Trim(window.clipboardData.getData(&quot;Text&quot;)))
                            
                            If Len(strDescription) &lt;&gt; 0 Then
                                .WriteLine vbTab &amp; strDescription
                            End If
                        End If
                        
                        .WriteLine String(79, &quot;=&quot;)
                    Else
                        .WriteLine String(79, &quot;-&quot;)
                    End If
                    .Write strSelectedText
                    .WriteLine
                    
                    .Close
                End With
                
                Set objTS       = Nothing
                Set objFSO      = Nothing
                Set objWshShell = Nothing
            Else
                window.alert &quot;Нет выделения&quot;
            End If
        &lt;/SCRIPT&gt;
    &lt;/HEAD&gt;
    &lt;BODY&gt;
    &lt;/BODY&gt;
&lt;/HTML&gt;</code></pre></div><p>Установить в контекстное меню IE (SaveIESelectedTextOn.reg):<br /></p><div class="codebox"><pre><code>Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Сохранить выделенный текст в файл]

[HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Сохранить выделенный текст в файл]
@=&quot;C:\\Program Files\\SaveIESelectedText\\SaveIESelectedText.htm&quot;
&quot;Flags&quot;=dword:00000000
&quot;Contexts&quot;=dword:00000011</code></pre></div><p>Удалить из контекстного меню IE (SaveIESelectedTextOff.reg):<br /></p><div class="codebox"><pre><code>Windows Registry Editor Version 5.00

[-HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Сохранить выделенный текст в файл]</code></pre></div><p>Настройки, которые берутся из ветки реестра <strong>HKEY_CURRENT_USER\Software\SaveIESelectedText</strong> (если они там есть):<br /></p><div class="quotebox"><blockquote><p>LastURL (REG_SZ)<br />UseDescription (REG_DWORD)<br />Path (REG_EXPAND_SZ)</p></blockquote></div><p>Автор скрипта - <strong>alexii</strong>.</p><p>Отдельное спасибо <strong>wisgest</strong> за исправление ошибки с неправильным формированием пути к файлу «SaveIESelectedText.txt».</p>]]></content>
			<author>
				<name><![CDATA[The gray Cardinal]]></name>
				<uri>https://forum.script-coding.com/profile.php?id=2</uri>
			</author>
			<updated>2008-01-24T20:28:23Z</updated>
			<id>https://forum.script-coding.com/viewtopic.php?pid=8295#p8295</id>
		</entry>
</feed>
