is there a way to call this function in the google console?
I am new to coding but I need this.
e[dt.a.LUCKY_POT] = function(e) {
return j.createElement(j.Suspense, {
fallback: null
}, j.createElement(bt, {
onClose: function() {
return m(e)
},
notification: e,
userId: null == d ? void 0 : d.id
}))
}
you're basically assigning a function to a variable called e[dt.a.LUCKY_POT]
so just call e[dt.a.LUCKY_POT](), but the question is what is the e object?
if you just want to run it and get the results - run the folloing:
(function(e) {
return j.createElement(j.Suspense, {
fallback: null
}, j.createElement(bt, {
onClose: function() {
return m(e)
},
notification: e,
userId: null == d ? void 0 : d.id
}))
})()
but then I'll ask who's the j object?
Related
Example
Json
let Settings = {
"Policy": {
"allowP": true,
"allowC": false,
}
}
How can i access get value using following syntax
console.log( Policy.allowP ); // should return true
console.log( Policy.value.allowP ); // should also return true
i tried following using javascript proxy
let createProxy = (settings : any) => {
const p = new Proxy(settings, {
get(target, p, _r) {
debugger;
if (p === "value") {
return settings;
}
return (target as any)[p];
},
});
return p;
}
let getSettings = () => {
var settings = Settings;
const p = new Proxy(settings, {
get(target, p, _r) {
debugger;
if (p === "value") {
return createProxy(settings);
}
return createProxy((target as any)[p]);
},
});
return p;
};
Tried to create Nested proxy so that i can access values using key.value syntax.
Is this correct way to implement it ? or is there any better way ?
Hello and big thanks for a all S.O community
I come today because i try to create local storage with Javascript for my users can change background and page settings on my website and find it back when page reload.
I tried many attempt but i'm so beginner for do make it work
var m = new s.a.Store({
modules: {
programs: p,
preferences: {
state: {
background: "images/backgrounds/background2.jpg",
preferredColor: "#1e90ff",
isWiFiConnected: !1
},
getters: {
background: function(t) {
return t.background
},
preferredColor: function(t) {
return t.preferredColor
},
isWiFiConnected: function(t) {
return t.isWiFiConnected
}
},
actions: {},
mutations: {
changePreferredColor: function(t, e) {
t.preferredColor = e
},
changeBackground: function(t, e) {
t.background = e
},
toggleWiFiConnection: function(t) {
t.isWiFiConnected = !t.isWiFiConnected
}
}
},
filesystem: d
},
strict: !1
});
i.a.prototype.$t = function(t) {
return t
}, i.a.config.devtools = !0, new i.a({
el: "#app",
store: m,
components: {
App: a.a
}
})
},
function(t, e, n) {
"use strict";
(function(e, n) {
var r = Object.freeze({});
function i(t) {
return null == t
}
function o(t) {
return null != t
}
function a(t) {
return !0 === t
}
function s(t) {
return "string" == typeof t || "number" == typeof t || "symbol" == typeof t || "boolean" == typeof t
}
function u(t) {
return null !== t && "object" == typeof t
}
there is the code i tried to add just before without sucess (blank page) :
var m = { ...localStorage };
localStorage.getItem("background");
localStorage.setItem("background");
Thanks for your support
Best regards
So I have an object called settings with a property called hex, which has its own properties:
var settings = {
hex: {
hex: "4fdaef",
validate: function(){
if(this.hex.length == 6){
return true
}
}
}
}
So currently to get the value of hex I would have to call settings.hex.hex, however ideally I would prefer to be able to call just settings.hex to get the value of the hex. How would I achieve this?
You'll have to rename hex to _hex, but this will work:
var settings = {
get hex() {
return this._hex.hex;
},
_hex: {
hex: "4fdaef",
validate: function () {
if (this.hex.length == 6) {
return true
}
}
}
}
console.log(settings.hex); // 4fdaef
With a Proxy you can allow for settings.hex.validate() to call _settings._hex._hex.validate(), but it's getting real ugly real quick, and we haven't even yet implemented the setter necessary for expected behavior of settings.hex = 'some other color'.
var _settings = {
_hex: {
_hex: new String('4fdaef'),
validate: function () {
if (this.length == 6) {
return true;
}
},
}
}
_settings._hex.hex = new Proxy(_settings._hex._hex, {
get(target, property) {
return property == 'validate' ? _settings._hex.validate : target[property];
}
});
const settings = new Proxy(_settings, {
get(target, property) {
return property == 'hex' ? target._hex.hex : target[property];
}
});
console.log(settings.hex); // [String: '4fdaef']
console.log(settings.hex.validate()); // true
I am making a simple chrome extension and want to overwrite a javascript function on a page. The javascript is too complex for me too understand. This is a part of the code:
}), define("components/Payout", ["react", "game-logic/clib", "game-logic/stateLib"], function(e, t, n) {
var r = e.DOM;
return e.createClass({
displayName: "Payout",
mixins: [e.addons.PureRenderMixin],
propTypes: {
engine: e.PropTypes.object.isRequired
},
getInitialState: function() {
return {
payout: 0
}
},
componentDidMount: function() {
window.requestAnimationFrame(this.draw)
},
draw: function() {
if (this.isMounted()) {
var e = t.calcGamePayout(t.getElapsedTimeWithLag(this.props.engine));
e ? this.setState({
payout: e * n.currentPlay(this.props.engine).bet
}) : this.setState({
payout: null
}), window.requestAnimationFrame(this.draw)
}
},
render: function() {
var e = n.currentPlay(this.props.engine).bet < 1e4 ? 2 : 0;
return r.span({
id: "payout"
}, t.formatSatoshis(this.state.payout, e))
}
})
}),
The function i want to 'hijack' is the "render" function. How would i go about that from an external JS file?
What i want is to replace the content of that function with something adjusted.
If the variable obj contains the object returned by that code, you can assign to obj.render:
obj.render = function() {
// your code here
};
Note that your code won't be able to use the r, t, or n variables like the original render function does. Those variables are only available in the original scope, and your function is outside that scope.
If you want to be able to call the original render method, you can do:
var orig_render = obj.render;
obj.render = function() {
var oldrender = orig_render.bind(this);
// your code here, call oldrender() to call original version
};
This is called monkey patching.
I have an object like this one:
var BrowserDetect = {
uniqueProps: [],
browserUID: '',
browserFonts: '',
isIPhonePad: function() {
return navigator.userAgent.match(/iPhone|iPod/i);
},
isDesktop: function() {
return !navigator.userAgent.match(/iPhone|iPad|android/i);
},
isAndroid: function() {
return navigator.userAgent.match(/android/i);
},
isFirefox: function() {
return navigator.userAgent.match(/firefox/i);
},
isIOS7: function() {
return navigator.userAgent.match(/.*CPU.*OS 7_\d/i);
},
isChromeCrios: function() {
return navigator.userAgent.match(/chrome|crios/i);
},
isIPad: function() {
return navigator.userAgent.match(/iPad/i);
}
}
(FYI: There are more functions inside the object)
So I want to go through "BrowserDetect" and check which of those functions inside it return "true" and get the function's name too.
What's the easy way to achieve that? I tried to use the jquery $.each, but without success.
Use Object.keys() with Array#filter to iterate the object and return all truthy function names:
Object.keys(BrowserDetect).filter(function(key) {
var f = BrowserDetect[key];
return typeof f === 'function' && f();
});
var BrowserDetect = {
uniqueProps: [],
browserUID: '',
browserFonts: '',
isIPhonePad: function() {
return navigator.userAgent.match(/iPhone|iPod/i);
},
isDesktop: function() {
return !navigator.userAgent.match(/iPhone|iPad|android/i);
},
isAndroid: function() {
return navigator.userAgent.match(/android/i);
},
isFirefox: function() {
return navigator.userAgent.match(/firefox/i);
},
isIOS7: function() {
return navigator.userAgent.match(/.*CPU.*OS 7_\d/i);
},
isChromeCrios: function() {
return navigator.userAgent.match(/chrome|crios/i);
},
isIPad: function() {
return navigator.userAgent.match(/iPad/i);
}
};
var result = Object.keys(BrowserDetect).filter(function(key) {
var f = BrowserDetect[key];
return typeof f === 'function' && f();
});
console.log(result);
I implemented a non-functional solution in pure js. It's fairly straightforward once you consider that a property can be a function as well. Once you use call() method on the property it will run the underlying function.
var BrowserDetect = {
uniqueProps: [],
browserUID: '',
browserFonts: '',
isIPhonePad: function() {
return navigator.userAgent.match(/iPhone|iPod/i);
},
isDesktop: function() {
return !navigator.userAgent.match(/iPhone|iPad|android/i);
},
isAndroid: function() {
return navigator.userAgent.match(/android/i);
},
isFirefox: function() {
return navigator.userAgent.match(/firefox/i);
},
isIOS7: function() {
return navigator.userAgent.match(/.*CPU.*OS 7_\d/i);
},
isChromeCrios: function() {
return navigator.userAgent.match(/chrome|crios/i);
},
isIPad: function() {
return navigator.userAgent.match(/iPad/i);
}
}
var functions = [];
for(var prop in BrowserDetect){
if(typeof(BrowserDetect[prop])=="function" && BrowserDetect[prop].call()){
functions.push(prop);
}
}
console.log(functions);
You can use common for ... in loop
for (var functionName in BrowserDetect) {
if (!BrowserDetect.hasOwnProperty(functionName)
|| typeof BrowserDetect[functionName] !== "function") continue
if (BrowserDetect[functionName]())
return functionName
}
or Object.keys
Object.keys(BrowserDetect).reduce(
(current, fnName) => typeof BrowserDetect[fnName] === "function" && BrowserDetect[fnName]() ? fnName : current )