Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 695

Help: Rainmeter Skins • Re: Weather Skins Not Working

$
0
0
Yes, I'll wait and I'm ready to test.
Well, it took a little longer because I had some WebView issues I had to solve before getting into this, since communicating between the plugin and the skin via the RainmeterAPI object was key in this case, but here it is...

[SkinFolder]\@Resources\Page.html:

Code:

<!DOCTYPE html><html>  <body style="margin: 0; background-color: red;">    <script>      var r = new XMLHttpRequest(), p = "";      r.onreadystatechange = function() {if (r.readyState == 4 && r.status == 200) {p = r.response; RainmeterAPI.Bang('[!SetOption Data String """' + p + '"""][!UpdateMeasure Data][!UpdateMeter *][!Redraw]');};};      r.open("GET", `https://api.allorigins.win/get?url=${encodeURIComponent("https://google.com")}`, true); r.responseType = "text"; r.send();    </script>  </body></html>
[SkinFolder]\Skin.ini:

Code:

[Rainmeter]Update=1000AccurateText=1DynamicWindowSize=1---Measures---[Page]Measure=PluginPlugin=WebViewX=0Y=0W=5H=5URL=file:///#@#Page.htmlUpdateDivider=-1[Data]Measure=StringString=UpdateDivider=-1RegExpSubstitute=1Substitute='(?siU)(?:^.*lang=(.*)>.*$|^.*$)':"\1",'\\(?=")':"","^\\\d+$":""---Meters---[Background]Meter=ShapeShape=Rectangle 0,0,600,350 | Fill Color 0,0,0,128 | StrokeWidth 0 | Stroke Color 0,0,0,0[PageData]Meter=StringX=(600/2)Y=(350/2)W=600H=350FontFace=ConsolasFontSize=12FontColor=255,255,255,255FontEffectColor=0,0,0,255StringEffect=ShadowStringAlign=CenterCenterAntiAlias=1ClipString=2MeasureName=DataText=Language: %1
Preview:
WebViewPageData.jpg
This uses the Page.html code to get the page source of the google.com site. The Substitute in the .ini can be adjusted to extract a different part of the response from the page source (here, the value of lang is left in the string, somewhat similar to how RegExp options work in a WebParser measure). Getting the response makes use of this nice and free API to bypass CORS and get the response even if ran from the above local webpage. I don't know if it will work with your CloudFlare / Captcha issue though, but for "normal" cases and sites, it will, as you can see from the screenshot.

P.S. The local page doesn't really need to be shown in the skin, since the response is passed to the [Data] measure automatically by the RainmeterAPI.Bang() part of the Javascript code, but I let it as a red 5 x 5 pixel "dot" in the top left corner of the skin, in case it's needed. If you want to see if getting the entire page source for a site works, just comment out (i.e. precede lines in the .ini with a ; symbol) the RegExpSubstitute and Substiitute lines, save the .ini and refresh the skin (the text will wrap and be clipped to fit the skin area, so it'll be just the part at the start of the desired page source).

P.S.S. In the Javascript code above, I used the "deprecated" XMLHttpRequest() to get the response. The "modern" fetch() can be used instead, if needed.

Statistics: Posted by Yincognito — Today, 2:18 pm



Viewing all articles
Browse latest Browse all 695

Trending Articles