There's a game called "duelingbook.com", it's a yugioh sandbox game, and it has hidden features that unlock themselves if you have a named card, but obviously as a sandbox game it's not locked at all, but instead it's UI locked. I tried to make the following extension and no amount of iteration allows me to override the "findCard" function to unlock all features to commit actions faster ( except for "Question" which locks you from checking your graveyard )
What I want is an extension that mimics pressing CTRL + SHIFT + I, and writing there the contents of contentscript.js, which works flawlessly. I am using Edge, but I imagine they are identical.
manifest.json
{
"name": "Page Redder",
"action": {},
"manifest_version": 3,
"version": "0.1",
"description": "Turns the page red when you click the icon",
"content_scripts": [
{
"matches": ["https://*.duelingbook.com/*"],
"all_frames": true,
"js": ["contentScript.js"]
}]
}
contentScript.js
function findCard(arr, hand, grave, like)
{
var cards = [player1.m1, player1.m2, player1.m3, player1.m4, player1.m5, player1.s1, player1.s2, player1.s3, player1.s4, player1.s5, player1.pendulumLeft, player1.pendulumRight, player1.fieldSpell, player2.m1, player2.m2, player2.m3, player2.m4, player2.m5, player2.s1, player2.s2, player2.s3, player2.s4, player2.s5, player2.pendulumLeft, player2.pendulumRight, player2.fieldSpell, linkLeft, linkRight, player1.skillCard, player2.skillCard];
if (hand)
{
for (var k = 0; k < player1.hand_arr.length; k++)
{
cards.push(player1.hand_arr[k]);
}
}
if (grave)
{
for (k = 0; k < player1.grave_arr.length; k++) {
cards.push(player1.grave_arr[k]);
}
}
for (var i = 0; i < arr.length;i ++)
{
if(arr[i] == "Question")
{
for (var j = 0; j < cards.length; j++)
{
if (cards[j])
{
if (cards[j].data("face_down"))
{ // Question
continue;
}
//if (cards[j].data("cardfront").data("treated_as") == arr[i] && !cards[j].data("face_down")) {
if (((cards[j].data("cardfront").data("treated_as") == arr[i] || like && cards[j].data("cardfront").data("treated_as") && cards[j].data("cardfront").data("treated_as").indexOf(arr[i]) >= 0)) == false)
{
return false;
}
}
}
}
}
return true;
}
Solved! It's a matter of understanding that by default, chrome extensions suffer from "isolation", and you need to set the "world" to "MAIN"
https://github.com/eyal282/chrome-ext-dueling-book-unlock
Related
Inside nested for loop I am using if/else if else condition. When if and else if condition are false, final else condition is running as expected but as it is in for loop instead of just running once it is running multiple times. What changes do i need to make to make else condition work only once?
Here is my code
productCodes: string[] = [],
vehicleType: string[] = [],
for (var i = 0; i < urls.length; i++) {
return https.get(urls[i], res => {
res.on('data', function(chunk) {
json += chunk;
});
res.on('end', function() {
var result = JSON.parse(json);
for (var i = 0; i < result.length; i++) {
for (var j = 0; j < result[i].products.length; j++) {
if (productCodes.length !== 0 && productCodes !== undefined) {
for (var k = 0; k < productCodes.length; k++) {
if (result[i].products[j].productCode == productCodes[k]) {
console.log(
'Product Codes: ' +
result[i].products[j].productCode
);
}
}
} else if (
vehicleType.length !== 0 &&
vehicleType !== undefined
) {
for (var k = 0; k < vehicleType.length; k++) {
if (result[i].products[j].productType == vehicleType[k]) {
console.log(
'Product Codes: ' +
result[i].products[j].productCode
);
}
}
} else {
console.log('No data');
break; ------------------------> HERE
}
}
}
});
});
}
```
If the loops are to cease after you encounter your last "else" statement I would recommend breaking them, if necessary using labels.
Here is a related question! It's for java, but the syntax is similar.
If it is just about only displaying the message once, consider just setting a boolean, then asking for it after the loops have concluded, and if true log the message.
EDIT: To expand my answer for your edit, I am not sure what exactly your desired behaviour would be, but chances are you want to break a loop deeper down than the topmost one. break; will break the topmost loop, in your case I believe that would be
for (var j = 0; j < result[i].products.length; j++)
But not the loop directly above that, iterating over this loop all over again.
Try assigning a label to the loop you want to break further down, and then break that one specifically.
EDIT 2:
I've modified your code to include the example of labels. That way, you can break whichever loop you actually want to end. Just comment the appropriate break back in. Hope this is helpful!
productCodes: string[] = [],
vehicleType: string[] = [],
outer1:
for (var i = 0; i < urls.length; i++)
{
return https.get(urls[i], res =>
{
res.on('data', function(chunk)
{
json += chunk;
});
res.on('end', function()
{
var result = JSON.parse(json);
middle1:
for (var i = 0; i < result.length; i++)
{
for (var j = 0; j < result[i].products.length; j++)
{
if (productCodes.length !== 0 && productCodes !== undefined)
{
for (var k = 0; k < productCodes.length; k++)
{
if (result[i].products[j].productCode == productCodes[k])
{
console.log(
'Product Codes: ' +
result[i].products[j].productCode
);
}
}
}
else if (
vehicleType.length !== 0 &&
vehicleType !== undefined
)
{
for (var k = 0; k < vehicleType.length; k++)
{
if (result[i].products[j].productType == vehicleType[k])
{
console.log(
'Product Codes: ' +
result[i].products[j].productCode
);
}
}
}
else
{
console.log('No data');
//break outer1;
//break middle1;
//break;
-- -- -- -- -- -- -- -- -- -- -- -- > HERE
}
}
}
});
});
}
As an additional note, nested labled loops or blocks like these are fairly uncommon due to the tendency to be able to resolve loops things in their own individual functions and then simply call those. I'd advise you to take a look at the java-based answer I linked above if you wanted to look into that.
For my App Dev 2 project, we were told to make a basic Blackjack game on Android Studio. The problems revolve around the Stand button. Anytime I press it, the app closes. Another issue is that whenever the button does work, it will replace the dealer's first card with their second card, when I need the second facedown card to be replaced with the second faceup card. I will link everything pertaining to this issue, as the whole program is too large for stackoverflow.
public ImageView dealer_Card1, dealer_Card2, dealer_Card3, dealer_Card4, dealer_Card5;
public ImageView player_Card1, player_Card2, player_Card3, player_Card4, player_Card5;
public void btn_Stand_Click() {
do {
dealer_Call();
calculate_Dealer_Score();
if (dealer_Score > 21) {
for (int i = 0; i < 5; i++) {
if (dealer_Card_Array[i] == 'A' && dealer_Score_Count[i] == 11) {
dealer_Score_Count[i] = 1;
break;
}
}
calculate_Dealer_Score();
}
} while (dealer_Score < 17 && dealer_Score <= player_Score && dealer_Card_Number < 5);
results();
}
public void btn_Stand(View view) {
do {
dealer_Call();
calculate_Dealer_Score();
if (dealer_Score > 21) {
for (int i = 0; i < 5; i++) {
if (dealer_Card_Array[i] == 'A' && dealer_Score_Count[i] == 11) {
dealer_Score_Count[i] = 1;
break;
}
}
calculate_Dealer_Score();
}
} while (dealer_Score < 17 && dealer_Score <= player_Score && dealer_Card_Number < 5);
if (player_Score == 21) {
black_Jack();
} else if (dealer_Score == 21) {
dealer_black_Jack();
} else if (dealer_Score > 21) {
total = total + (bet * 2);
Toast toast = Toast.makeText(getApplicationContext(), "Dealer Bust! You won!", Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
disable_Buttons();
alert_Box();
} else results();
}
private void card_Image_Switcher() {
dealer_Card1.setImageResource(R.drawable.cardback);
dealer_Card2.setImageResource(R.drawable.cardback);
dealer_Card3.setImageResource(R.drawable.cardback);
dealer_Card4.setImageResource(R.drawable.cardback);
dealer_Card5.setImageResource(R.drawable.cardback);
player_Card1.setImageResource(R.drawable.cardback);
player_Card2.setImageResource(R.drawable.cardback);
player_Card3.setImageResource(R.drawable.cardback);
player_Card4.setImageResource(R.drawable.cardback);
player_Card5.setImageResource(R.drawable.cardback);
}
I have a kendo grid and I can export its data into excel file without any problem. In my grid, some columns may be hidden because they do not have any value. However, I want even these hidden columns (I mean their header) be in my exported excel file.
Here is a piece of code showing the excel config in my Kendo grid configuration.
excel: {
fileName: new Date().toString() + ".xlsx",
allPages: true,
},
Any help would be appreciated.
You can have columns in an array which defines hidden: true and then simply traverse through columns array and show/hide columns just before export as following:
function excelExport(e) {
if (!exportFlag) {
for(var i=0; i < columns.length; i++) {
if(columns[i].hidden)
e.sender.showColumn(i);
}
e.preventDefault();
exportFlag = true;
setTimeout(function () {
e.sender.saveAsExcel();
});
} else {
for(var i=0; i < columns.length; i++) {
if(columns[i].hidden)
e.sender.hideColumn(i);
}
exportFlag = false;
}
}
You can add some javascript to control this.
var exportFlag = true;
$("#gridName").data("kendoGrid").bind("excelExport", function (e) {
if (exportFlag) {
e.sender.showColumn("hiddenColumnName");
e.preventDefault();
exportFlag = false;
e.sender.saveAsExcel();
} else {
e.sender.hideColumn("hiddenColumnName");
exportFlag = true;
}
});
Basically this catches the excelExport event when you click the Export button and shows the hidden column in your grid before it fires the saveAsExcel() function which saves your document. Then it hides the column again.
Here is an Example you can test with.
I was looking to achieve a similar thing and used the answer provided by #Ankur with slight modification as I needed to hide the columns again after the export.
Code as follows:
excelExport(e) {
Spa.startLoading(); // loading overlay to hide the columns showing then hiding again
var columns = e.sender.columns;
var hiddenColumnNumbers = [];
if (!exportFlag) {
for (let i = 0; i < columns.length; i++) {
if (columns[i].hidden) {
e.sender.showColumn(i);
hiddenColumnNumbers.push(i);
}
}
e.preventDefault();
exportFlag = true;
setTimeout(() => {
e.sender.saveAsExcel();
for (let j = 0; j < columns.length; j++) {
if (hiddenColumnNumbers.indexOf(j) > -1) {
e.sender.hideColumn(j);
}
}
Spa.stopLoading(); // hide loading overlay
});
} else {
for (let k = 0; k < columns.length; k++) {
if (columns[k].hidden)
e.sender.hideColumn(k);
}
exportFlag = false;
Spa.stopLoading(); // hide loading overlay
}
},
I got a question regarding the use of tween.js with three.js
I've been trying to get a color tween to work that triggers on a mousedown.
However it's not triggering the tween, and not giving any errors.
I'm at a loss :(
for (var i = 0; i < scene.children.length; i++) {
if (scene.children[i].position.z <= maxPositionZ && scene.children[i].position.z >= minPositionZ) {
if (scene.children[i].position.y <= maxPositionY && scene.children[i].position.y >= minPositionY) {
if (scene.children[i].position.x <= maxPositionX && scene.children[i].position.x >= minPositionX) {
timer = timer + tweenSpeed
doTimeout(i,timer);
}
}
}
}
function doTimeout(i,timer){
var fadeouttimer = 1000 + timer
setTimeout(function() {
var tween = new TWEEN.Tween(scene.children[i].children[0].material.color).to({r: 1, g: 0, b: 0 }, 200).start()
}, timer);
}
The awnser for my question, was that the TWEEN.update(); in the render function should be seperated in its's own function. It cannot be in the same function as requestAnimationFrame()
function render() {
TWEEN.update();
renderer.render(scene, camera);
}
I tried the solution in Distinguish Chrome from Safari using jQuery.browser but it doesnt work. This solution does but i dont have any way of getting the real version numbers:
$.browser.chrome = $.browser.webkit && !!window.chrome;
$.browser.safari = $.browser.webkit && !window.chrome;
I need to detect the full version numbers so that i can block older versions of these (because their slow/buggy, not for features).
You could use straight Javascript:
if(navigator.userAgent.toLowerCase().indexOf('Chrome'))
{
var n=navigator.userAgent.split(" ");
var curVersion="";
for (var i = 0; i < n.length; i++)
{
if(n[i].indexOf("Chrome"))
{
curVersionTmp=n[i].split("/");
curVersion = curVersionTmp[1];
}
}
}
else if(navigator.userAgent.toLowerCase().indexOf('applewebkit'))
{
var n=navigator.userAgent.split(" ");
var curVersion="";
for (var i = 0; i < n.length; i++)
{
if(n[i].indexOf("Version"))
{
curVersionTmp=n[i].split("/");
curVersion = curVersionTmp[1];
}
}
}
http://www.useragentstring.com/pages/Safari/