Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion ep_gui/resources/settings.reg
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,10 @@
;x 3 %R:1542%
;x 1 %R:1543%
"WeatherWindowCornerPreference"=dword:00000002
;c 2 %R:1544%
;c 3 %R:1544%
;x 0 %R:1545%
;x 1 %R:1546%
;x 2 ExplorerPatcher
"WeatherIconPack"=dword:00000000
;c 2 %R:1547%
;x 0 %R:1548%
Expand Down
3 changes: 2 additions & 1 deletion ep_gui/resources/settings10.reg
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,10 @@
;x 1 %R:1538%
;x 2 %R:1539%
"WeatherTheme"=dword:00000000
;c 2 %R:1544%
;c 3 %R:1544%
;x 0 %R:1545%
;x 1 %R:1546%
;x 2 ExplorerPatcher
"WeatherIconPack"=dword:00000000
;c 2 %R:1547%
;x 0 %R:1548%
Expand Down
1 change: 1 addition & 0 deletions ep_weather_host/ep_weather.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,5 @@ DEFINE_GUID(IID_IEPWeather,

#define EP_WEATHER_ICONPACK_MICROSOFT 0
#define EP_WEATHER_ICONPACK_GOOGLE 1
#define EP_WEATHER_ICONPACK_OPEN 2
#endif
95 changes: 66 additions & 29 deletions ep_weather_host/ep_weather_host.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "ep_weather_host.h"
#include "resource.h"
#include "ep_weather_provider_google_html.h"
#include "ep_weather_provider_google_script.h"
#include "ep_weather_error_html.h"
Expand Down Expand Up @@ -363,6 +364,46 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_NavigateToProvider(EPWeather* _this)
return hr;
}

static LPWSTR _epw_Weather_BuildOpenIconScript(void)
{
const WORD resourceIds[] = {IDR_WEATHER_OPEN_ARTWORK, IDR_WEATHER_OPEN_CONDITIONS, IDR_WEATHER_OPEN_FORECAST, IDR_WEATHER_OPEN_RENDER};
const WCHAR prefix[] = EP_WEATHER_GOOGLE_ICON_HELPER L"(() => {\n";
const WCHAR suffix[] = L"\n})();";
const char* resources[ARRAYSIZE(resourceIds)];
DWORD lengths[ARRAYSIZE(resourceIds)];
size_t capacity = ARRAYSIZE(prefix) + ARRAYSIZE(suffix);

for (size_t i = 0; i < ARRAYSIZE(resourceIds); ++i)
{
HRSRC resource = FindResourceW(epw_hModule, MAKEINTRESOURCEW(resourceIds[i]), RT_RCDATA);
if (!resource) return NULL;
HGLOBAL contents = LoadResource(epw_hModule, resource);
resources[i] = contents ? LockResource(contents) : NULL;
lengths[i] = SizeofResource(epw_hModule, resource);
if (!resources[i] || !lengths[i] || lengths[i] > INT_MAX) return NULL;
capacity += lengths[i] + 1;
}

LPWSTR script = malloc(capacity * sizeof(WCHAR));
if (!script) return NULL;
size_t offset = ARRAYSIZE(prefix) - 1;
memcpy(script, prefix, offset * sizeof(WCHAR));
for (size_t i = 0; i < ARRAYSIZE(resourceIds); ++i)
{
int chars = MultiByteToWideChar(CP_UTF8, MB_ERR_INVALID_CHARS, resources[i], (int)lengths[i],
script + offset, (int)lengths[i]);
if (!chars)
{
free(script);
return NULL;
}
offset += chars;
script[offset++] = L'\n';
}
memcpy(script + offset, suffix, sizeof(suffix));
return script;
}

HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this)
{
HRESULT hr = S_OK;
Expand All @@ -372,39 +413,35 @@ HRESULT STDMETHODCALLTYPE _epw_Weather_ExecuteDataScript(EPWeather* _this)
}
else if (dwProvider == EP_WEATHER_PROVIDER_GOOGLE)
{
LPWSTR wszScriptData = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN);
if (wszScriptData)
LONG64 dwIconPack = InterlockedAdd64(&_this->dwIconPack, 0);
LPWSTR customScript = NULL;
if (dwIconPack == EP_WEATHER_ICONPACK_OPEN)
{
LONG64 dwIconPack = InterlockedAdd(&_this->dwIconPack, 0);
if (dwIconPack == EP_WEATHER_ICONPACK_MICROSOFT)
{
swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, L"%s%s%s%s%s%s", ep_weather_provider_google_script00, ep_weather_provider_google_script010, ep_weather_provider_google_script011, ep_weather_provider_google_script020, ep_weather_provider_google_script021, ep_weather_provider_google_script03);
}
else if (dwIconPack == EP_WEATHER_ICONPACK_GOOGLE)
{
swprintf_s(wszScriptData, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, ep_weather_provider_google_script10);
}
//wprintf(L"%s\n", _this->wszScriptData);
if (_this->pCoreWebView2)
{
GenericObjectWithThis* pCoreWebView2ExecuteScriptCompletedHandler =
GenericObjectWithThis_MakeAndInitialize(&EPWeather_ICoreWebView2ExecuteScriptCompletedHandlerVtbl, _this, L"pCoreWebView2ExecuteScriptCompletedHandler");
if (!pCoreWebView2ExecuteScriptCompletedHandler) hr = E_FAIL;
else hr = _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, wszScriptData, pCoreWebView2ExecuteScriptCompletedHandler);
}
else
{
hr = E_FAIL;
}
if (FAILED(hr))
customScript = _epw_Weather_BuildOpenIconScript();
}
else if (dwIconPack == EP_WEATHER_ICONPACK_MICROSOFT)
{
customScript = malloc(sizeof(WCHAR) * EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN);
if (customScript && swprintf_s(customScript, EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN, L"%s%s%s%s%s%s",
ep_weather_provider_google_script00, ep_weather_provider_google_script010, ep_weather_provider_google_script011,
ep_weather_provider_google_script020, ep_weather_provider_google_script021, ep_weather_provider_google_script03) < 0)
{
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
free(customScript);
customScript = NULL;
}
free(wszScriptData);
}
else
LPCWSTR script = customScript ? customScript : ep_weather_provider_google_script10;
hr = E_FAIL;
if (_this->pCoreWebView2)
{
hr = E_OUTOFMEMORY;
GenericObjectWithThis* callback =
GenericObjectWithThis_MakeAndInitialize(&EPWeather_ICoreWebView2ExecuteScriptCompletedHandlerVtbl, _this, L"pCoreWebView2ExecuteScriptCompletedHandler");
if (callback) hr = _this->pCoreWebView2->lpVtbl->ExecuteScript(_this->pCoreWebView2, script, callback);
}
free(customScript);
if (FAILED(hr))
{
InterlockedExchange64(&_this->bBrowserBusy, FALSE);
}
}
return hr;
Expand Down Expand Up @@ -1961,4 +1998,4 @@ HRESULT STDMETHODCALLTYPE epw_Weather_GetIconSize(EPWeather* _this, LONG64* cbx,
if (cbx) *cbx = InterlockedAdd64(&_this->cbx, 0);
if (cby) *cby = InterlockedAdd64(&_this->cby, 0);
return S_OK;
}
}
5 changes: 5 additions & 0 deletions ep_weather_host/ep_weather_host.rc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)

IDR_WEATHER_OPEN_ARTWORK RCDATA "open_icons\\artwork.js"
IDR_WEATHER_OPEN_CONDITIONS RCDATA "open_icons\\conditions.js"
IDR_WEATHER_OPEN_FORECAST RCDATA "open_icons\\forecast.js"
IDR_WEATHER_OPEN_RENDER RCDATA "open_icons\\render.js"

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
Expand Down
7 changes: 6 additions & 1 deletion ep_weather_host/ep_weather_host.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@
<Midl Include="..\ep_weather_host_stub\ep_weather_host.idl" />
</ItemGroup>
<ItemGroup>
<None Include="open_icons\artwork.js" />
<None Include="open_icons\conditions.js" />
<None Include="open_icons\forecast.js" />
<None Include="open_icons\render.js" />
<None Include="open_icons\CC0-1.0.txt" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand All @@ -327,4 +332,4 @@
</PropertyGroup>
<Error Condition="!Exists('..\packages\Microsoft.Web.WebView2.1.0.3967.48\build\native\Microsoft.Web.WebView2.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Web.WebView2.1.0.3967.48\build\native\Microsoft.Web.WebView2.targets'))" />
</Target>
</Project>
</Project>
38 changes: 19 additions & 19 deletions ep_weather_host/ep_weather_provider_google_script.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
// many thanks to https://stackoverflow.com/questions/23202966/google-weather-widget-on-my-website
#define EP_WEATHER_PROVIDER_GOOGLE_SCRIPT_LEN 30000

LPCWSTR ep_weather_provider_google_script10 = L"var final_im = 0; function ep_weather_part0() { return \"run_part_0\"; }; ep_weather_part0();";
#define EP_WEATHER_GOOGLE_ICON_HELPER \
L"function ep_weather_icon() {\n" \
L" var im = document.querySelector('#wob_wc img') || document.querySelector('img.YQ4gaf.zr758c');\n" \
L" if (!im) { throw new Error('Google weather icon not found; page layout may have changed'); }\n" \
L" return im;\n" \
L"}\n"

LPCWSTR ep_weather_provider_google_script10 = EP_WEATHER_GOOGLE_ICON_HELPER
L"var final_im = 0; function ep_weather_part0() { return \"run_part_0\"; }; ep_weather_part0();";

// reference: https://github.com/Triggertrap/sun-js
LPCWSTR ep_weather_provider_google_script00 = L"\
LPCWSTR ep_weather_provider_google_script00 = EP_WEATHER_GOOGLE_ICON_HELPER L"\
Date.prototype.sunrise = function(latitude, longitude, zenith) {\n\
return this.sunriseSet(latitude, longitude, true, zenith);\n\
}\n\
Expand Down Expand Up @@ -101,11 +109,6 @@ Math.mod = function(a, b) {\n\
}\n\
\n\
\n\
function ep_weather_icon() {\n\
var im = document.querySelector('#wob_wc img') || document.querySelector('img.YQ4gaf.zr758c');\n\
if (!im) { throw new Error('Google weather icon not found; page layout may have changed'); }\n\
return im;\n\
}\n\
var is_first_time = 1;\n\
var final_im = 0;\n\
var final_img2 = 0;\n\
Expand Down Expand Up @@ -347,14 +350,14 @@ function ep_weather_getData(image, w, h, ch) {\n\
return res;\n\
}\n\
var ep_result;\n\
function ep_weather_part1() {\n\
let unit = Array.from(document.getElementsByClassName('wob-unit')[0].getElementsByTagName('span')).filter(e => e.className == 'wob_t')[0].innerText;\n\
let p = '%c';\n\
if (!unit.includes(p)) {\n\
Array.from(document.getElementsByClassName('wob-unit')[0].getElementsByTagName('a')).filter(e => e.className == 'wob_t').filter(e => e.innerText.includes(p))[0].click();\n\
unit = 'x';\n\
}\n\
ep_result = ep_weather_getData(\n(final_im != 0) ? final_im : ep_weather_icon(), %d, %d, unit);\n\
function ep_weather_part1() {\n\
return \"run_part_2\";\n\
}\n\
ep_weather_part1();\n\
Expand All @@ -369,21 +372,18 @@ window.scrollTo(LeftScroll, TopScroll);\n\
};\n\
}\n\
function ep_weather_part2() {\n\
let h = document.getElementsByClassName(\"ULSxyf\")[0].offsetHeight;\n\
////document.getElementsByClassName(\"google-weather-place\")[0].style.height = h + 'px';\n\
////document.getElementsByClassName(\"google-weather-crop\")[0].style.height = h + 'px';\n\
//if (1) for (let j = 0; j < document.styleSheets.length; j++) changeCSSStyle(j, '.wob_ds', 'background-color', '#303134');\n\
document.getElementsByClassName(\"KFFQ0c\")[0].style.display = 'none';\n\
if (document.getElementsByClassName(\"QS5gu sy4vM\").length > 1) { document.getElementsByClassName(\"QS5gu sy4vM\")[1].click(); return \"run_part_1\"; }\n\
if (document.getElementsByClassName(\"Gfzyee VDgVie DKlyaf Loxgyb\").length > 1) { document.getElementsByClassName(\"Gfzyee VDgVie DKlyaf Loxgyb\")[1].click(); return \"run_part_1\"; }\n\
//document.getElementById(\"search\").scrollIntoView(true);\n\
return ep_result;\n\
}\n\
let banner1 = document.getElementById(\"taw\"); if (banner1) { banner1.style = \"display: none\"; }\n\
let wob_gsp = document.getElementById(\"wob_gsp\"); if (wob_gsp) { wob_gsp.style = \"width: 648.04px\"; }\n\
let weird_line = document.getElementsByClassName(\"v5jHUb\")[0]; if (weird_line) { weird_line.style = \"display: none\"; }\n\
let slim_appbar = document.getElementById(\"slim_appbar\"); if (slim_appbar) { slim_appbar.style = \"display: none\"; }\n\
scrolldisable();\n\
const header = document.getElementsByClassName('KFFQ0c')[0];\n\
if (header) header.style.display = 'none';\n\
if (document.getElementsByClassName(\"QS5gu sy4vM\").length > 1) { document.getElementsByClassName(\"QS5gu sy4vM\")[1].click(); return \"run_part_1\"; }\n\
if (document.getElementsByClassName(\"Gfzyee VDgVie DKlyaf Loxgyb\").length > 1) { document.getElementsByClassName(\"Gfzyee VDgVie DKlyaf Loxgyb\")[1].click(); return \"run_part_1\"; }\n\
//document.getElementById(\"search\").scrollIntoView(true);\n\
return ep_result;\n\
}\n\
ep_weather_part2();\n\
";
#endif
#endif
121 changes: 121 additions & 0 deletions ep_weather_host/open_icons/CC0-1.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
Creative Commons Legal Code

CC0 1.0 Universal

CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
LEGAL SERVICES. DISTRIBUTION OF THIS DOCUMENT DOES NOT CREATE AN
ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
REGARDING THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS
PROVIDED HEREUNDER, AND DISCLAIMS LIABILITY FOR DAMAGES RESULTING FROM
THE USE OF THIS DOCUMENT OR THE INFORMATION OR WORKS PROVIDED
HEREUNDER.

Statement of Purpose

The laws of most jurisdictions throughout the world automatically confer
exclusive Copyright and Related Rights (defined below) upon the creator
and subsequent owner(s) (each and all, an "owner") of an original work of
authorship and/or a database (each, a "Work").

Certain owners wish to permanently relinquish those rights to a Work for
the purpose of contributing to a commons of creative, cultural and
scientific works ("Commons") that the public can reliably and without fear
of later claims of infringement build upon, modify, incorporate in other
works, reuse and redistribute as freely as possible in any form whatsoever
and for any purposes, including without limitation commercial purposes.
These owners may contribute to the Commons to promote the ideal of a free
culture and the further production of creative, cultural and scientific
works, or to gain reputation or greater distribution for their Work in
part through the use and efforts of others.

For these and/or other purposes and motivations, and without any
expectation of additional consideration or compensation, the person
associating CC0 with a Work (the "Affirmer"), to the extent that he or she
is an owner of Copyright and Related Rights in the Work, voluntarily
elects to apply CC0 to the Work and publicly distribute the Work under its
terms, with knowledge of his or her Copyright and Related Rights in the
Work and the meaning and intended legal effect of CC0 on those rights.

1. Copyright and Related Rights. A Work made available under CC0 may be
protected by copyright and related or neighboring rights ("Copyright and
Related Rights"). Copyright and Related Rights include, but are not
limited to, the following:

i. the right to reproduce, adapt, distribute, perform, display,
communicate, and translate a Work;
ii. moral rights retained by the original author(s) and/or performer(s);
iii. publicity and privacy rights pertaining to a person's image or
likeness depicted in a Work;
iv. rights protecting against unfair competition in regards to a Work,
subject to the limitations in paragraph 4(a), below;
v. rights protecting the extraction, dissemination, use and reuse of data
in a Work;
vi. database rights (such as those arising under Directive 96/9/EC of the
European Parliament and of the Council of 11 March 1996 on the legal
protection of databases, and under any national implementation
thereof, including any amended or successor version of such
directive); and
vii. other similar, equivalent or corresponding rights throughout the
world based on applicable law or treaty, and any national
implementations thereof.

2. Waiver. To the greatest extent permitted by, but not in contravention
of, applicable law, Affirmer hereby overtly, fully, permanently,
irrevocably and unconditionally waives, abandons, and surrenders all of
Affirmer's Copyright and Related Rights and associated claims and causes
of action, whether now known or unknown (including existing as well as
future claims and causes of action), in the Work (i) in all territories
worldwide, (ii) for the maximum duration provided by applicable law or
treaty (including future time extensions), (iii) in any current or future
medium and for any number of copies, and (iv) for any purpose whatsoever,
including without limitation commercial, advertising or promotional
purposes (the "Waiver"). Affirmer makes the Waiver for the benefit of each
member of the public at large and to the detriment of Affirmer's heirs and
successors, fully intending that such Waiver shall not be subject to
revocation, rescission, cancellation, termination, or any other legal or
equitable action to disrupt the quiet enjoyment of the Work by the public
as contemplated by Affirmer's express Statement of Purpose.

3. Public License Fallback. Should any part of the Waiver for any reason
be judged legally invalid or ineffective under applicable law, then the
Waiver shall be preserved to the maximum extent permitted taking into
account Affirmer's express Statement of Purpose. In addition, to the
extent the Waiver is so judged Affirmer hereby grants to each affected
person a royalty-free, non transferable, non sublicensable, non exclusive,
irrevocable and unconditional license to exercise Affirmer's Copyright and
Related Rights in the Work (i) in all territories worldwide, (ii) for the
maximum duration provided by applicable law or treaty (including future
time extensions), (iii) in any current or future medium and for any number
of copies, and (iv) for any purpose whatsoever, including without
limitation commercial, advertising or promotional purposes (the
"License"). The License shall be deemed effective as of the date CC0 was
applied by Affirmer to the Work. Should any part of the License for any
reason be judged legally invalid or ineffective under applicable law, such
partial invalidity or ineffectiveness shall not invalidate the remainder
of the License, and in such case Affirmer hereby affirms that he or she
will not (i) exercise any of his or her remaining Copyright and Related
Rights in the Work or (ii) assert any associated claims and causes of
action with respect to the Work, in either case contrary to Affirmer's
express Statement of Purpose.

4. Limitations and Disclaimers.

a. No trademark or patent rights held by Affirmer are waived, abandoned,
surrendered, licensed or otherwise affected by this document.
b. Affirmer offers the Work as-is and makes no representations or
warranties of any kind concerning the Work, express, implied,
statutory or otherwise, including without limitation warranties of
title, merchantability, fitness for a particular purpose, non
infringement, or the absence of latent or other defects, accuracy, or
the present or absence of errors, whether or not discoverable, all to
the greatest extent permissible under applicable law.
c. Affirmer disclaims responsibility for clearing rights of other persons
that may apply to the Work or any use thereof, including without
limitation any person's Copyright and Related Rights in the Work.
Further, Affirmer disclaims responsibility for obtaining any necessary
consents, permissions or other rights required for any use of the
Work.
d. Affirmer understands and acknowledges that Creative Commons is not a
party to this document and has no duty or obligation with respect to
this CC0 or use of the Work.
Loading