• R/O
  • HTTP
  • SSH
  • HTTPS

website: 提交

HTML source code, style-sheets, scripts, and images for deployment on mingw.osdn.io


Commit MetaInfo

修订版53358208c967d324855759a32dcf288dbb6830b4 (tree)
时间2021-09-12 23:38:38
作者Keith Marshall <keith@user...>
CommiterKeith Marshall

Log Message

Redirect OSDN mail archive searches from DuckDuckGo to Google.

* site.js (osdn_archive, ddg_query, ddg_widget): New functions; they
facilitate setup and initiation of a DuckDuckGo query of any OSDN mail
archive, with redirection via the Google search engine, using...
(ddg_bang, ddg_google_search, ddg_google_search_site): ...these new
internal-use helper functions.

* mailing.html (MinGW-Users, MinGW-Notify): Use...
(ddg_widget, osdn_archive): ...these to initiate DuckDuckGo search...
(ddg_google_search): ...with this to redirect to the Google engine.

更改概述

差异

--- a/mailing.html
+++ b/mailing.html
@@ -120,12 +120,20 @@ keyword searches within the OSDN.net (upper),
120120 and the SourceForge.net (lower box) archives, respectively.
121121 (If your question relates to MSYS, you may also wish to refer to the
122122 <a href="#mingw-msys">historical MinGW&#8209;MSYS archive, below</a>).
123+<!-- Search widget using DuckDuckGo, does not work well on OSDN! --><!--
123124 <form class="search" method="get" action="https://duckduckgo.com/" target="_blank">
124125 <button class="fa fa-search" type="submit"></button>
125126 <input type="text" name="q" placeholder="Search MinGW-Users on OSDN.net ..." />
126127 <input type="hidden" name="sites" value="https://osdn.net/projects/mingw/lists/archive/users" />
127128 <input type="hidden" name="kn" value="1" />
128129 </form>
130+--><!-- Alternative search widget, using Google, does work -->
131+<form class="search" onsubmit="ddg_widget(this).click()">
132+ <button class="fa fa-search" type="submit"
133+ onclick="return ddg_google_search(this, true, osdn_archive('mingw', 'users'))"
134+ ></button>
135+ <input type="text" name="q" placeholder="Search MinGW-Users on OSDN.net ..." />
136+</form>
129137 <form class="search" method="get" action="https://sourceforge.net/p/mingw/mailman/search/" target="_blank">
130138 <button class="fa fa-search" type="submit"></button>
131139 <input type="text" name="q" placeholder="Search MinGW-Users on SourceForge.net ..." />
@@ -155,12 +163,20 @@ while notifications posted prior to September&nbsp;2017 have been
155163 >archived, on SourceForge.net</a>.
156164 Once again, you may use the following pair of search boxes
157165 to perform keyword searches on these archives, respectively.
166+<!-- Search widget using DuckDuckGo, does not work well on OSDN! --><!--
158167 <form class="search" method="get" action="https://duckduckgo.com/" target="_blank">
159168 <button class="fa fa-search" type="submit"></button>
160169 <input type="text" name="q" placeholder="Search MinGW-Notify on OSDN.net ..." />
161170 <input type="hidden" name="sites" value="https://osdn.net/projects/mingw/lists/archive/notify" />
162171 <input type="hidden" name="kn" value="1" />
163172 </form>
173+--><!-- Alternative search widget, using Google, does work -->
174+<form class="search" onsubmit="ddg_widget(this).click()">
175+ <button class="fa fa-search" type="submit"
176+ onclick="return ddg_google_search(this, true, osdn_archive('mingw', 'notify'))"
177+ ></button>
178+ <input type="text" name="q" placeholder="Search MinGW-Notify on OSDN.net ..." />
179+</form>
164180 <form class="search" method="get" action="https://sourceforge.net/p/mingw/mailman/search/" target="_blank">
165181 <button class="fa fa-search" type="submit"></button>
166182 <input type="text" name="q" placeholder="Search MinGW-Notify on SourceForge.net ..." />
--- a/site.js
+++ b/site.js
@@ -98,4 +98,78 @@ function load_page( src )
9898 load_content( div, src );
9999 }
100100
101+/* Web-Search Widget Helper Functions
102+ * ----------------------------------
103+ * Derived from the DuckDuckGo.com search widget implementation by
104+ * Juri Wornowitski, as described at https://www.plainlight.com/ddg,
105+ * these facilitate incorporation of multiple search widget variants,
106+ * at multiple locations across the site.
107+ *
108+ */
109+function ddg_widget( ref )
110+{ /* Acquire a reference to the "submit" button, within the search
111+ * widget; the containing "form" element uses this to simulate a
112+ * click event, if the form is submitted by pressing the "enter"
113+ * key, when the "input" field has the focus.
114+ */
115+ ref = ref.getElementsByTagName( "button" );
116+ for( idx = 0; idx < ref.length; idx++ )
117+ if( ref[idx].type == "submit" ) return ref[idx];
118+ return undefined;
119+}
120+
121+function ddg_google_search_site( domain )
122+{ /* Encode a search "domain" as a "site:" reference, to be appended
123+ * to the query URL, when a DuckDuckGo.com search is directed to the
124+ * Google search engine, via DuckDuckGo.com's "bang" facility.
125+ */
126+ return "+".concat( encodeURIComponent( "site:".concat( domain )));
127+}
128+
129+function ddg_bang( src, query, domain )
130+{ /* Set up a query, using DuckDuckGo.com's "bang" facility, (directed
131+ * to the "bang" identified by "src"); append the query, appropriately
132+ * encoded, and optionally a "domain" URL whence the query results are
133+ * to be retrieved.
134+ */
135+ const bang = "https://duckduckgo.com?q=".concat( encodeURIComponent( "!" ));
136+ query = bang.concat( src.concat( "+".concat( encodeURIComponent( query ))));
137+ return query.concat( domain );
138+}
139+
140+function ddg_query( widget )
141+{ /* Retrieve the current value entered into the query "input" field;
142+ * (this is identified by having a "name" property value of "q").
143+ */
144+ widget = widget.getElementsByTagName( "input" );
145+ for( idx = 0; idx < widget.length; idx++ )
146+ if( widget[idx].name == "q" ) return widget[idx].value;
147+ return undefined;
148+}
149+
150+function ddg_google_search( widget, target, domain )
151+{ /* Initiate a Google search, from the DuckDuckGo.com search widget;
152+ * (the "widget" reference is initially associated with the "submit"
153+ * button, whence we retrieve the query context via the parent form).
154+ * If "domain" is not null, it is assumed to represent a "site:" URL,
155+ * where the search is to be performed, while boolean value "target"
156+ * indicates whether or not a new browser window is to be opened to
157+ * display the search results.
158+ */
159+ var query = ddg_query( widget.parentElement );
160+ if( domain.length > 0 ) domain = ddg_google_search_site( domain );
161+ if( target ) window.open( ddg_bang( "g", query, domain ));
162+ else ddg_bang( "g", query, domain );
163+ return false;
164+}
165+
166+function osdn_archive( project, list )
167+{ /* Construct a URL to represent the search domain for an OSDN.net
168+ * mailing list archive, for any specified "list", belonging to a
169+ * specified "project".
170+ */
171+ const template = "https://osdn.net/projects/%P%/lists/archive/";
172+ return template.replace( "%P%", project ).concat( list );
173+}
174+
101175 /* $RCSfile$: end of file */
Show on old repository browser