📄 surfhelper.cpp
字号:
}
pScriptElement = pDisp;
pDisp->Release();
if (!pScriptElement)
{
continue;
}
if (m_dwSettings & REMOVE_STATUS_MODIFIER ||
m_dwSettings & REMOVE_ONCONTEXTMENU ||
m_dwSettings & REMOVE_ONUNLOAD ||
m_dwSettings & REMOVE_TIMER)
{
pScriptElement->get_text(&bstrValue);
if (SysStringLen(bstrValue) > 0)
{
bChanged = FALSE;
try
{
if (m_dwSettings & REMOVE_STATUS_MODIFIER)
{
if (RandomReplaceString(
bstrValue, L"window.status", TRUE))
{
bChanged = TRUE;
}
}
if (m_dwSettings & REMOVE_ONCONTEXTMENU)
{
if (RandomReplaceString(
bstrValue, L"oncontextmenu", TRUE))
{
bChanged = TRUE;
}
}
if (m_dwSettings & REMOVE_ONUNLOAD)
{
if (RandomReplaceString(
bstrValue, L"onunload", TRUE))
{
bChanged = TRUE;
}
}
if (m_dwSettings & REMOVE_TIMER)
{
if (RemoveTimer(bstrValue))
{
bChanged = TRUE;
}
}
}
catch (...)
{
}
if (bChanged)
{
pScriptElement->put_text(bstrValue);
}
SysFreeString(bstrValue);
}
}
if (m_dwSettings & REMOVE_ONCONTEXTMENU ||
m_dwSettings & REMOVE_ONUNLOAD)
{
pScriptElement->get_event(&bstrValue);
if (SysStringLen(bstrValue) > 0)
{
if (m_dwSettings & REMOVE_ONCONTEXTMENU &&
wcsstr(bstrValue, L"oncontextmenu") != NULL)
{
pScriptElement->put_event(L"");
}
if (m_dwSettings & REMOVE_ONUNLOAD &&
wcsstr(bstrValue, L"onunload") != NULL)
{
pScriptElement->put_event(L"");
}
SysFreeString(bstrValue);
}
}
pScriptElement.Release();
}
}
}
}
}
break;
case DISPID_TITLECHANGE:
//
//remove popup by title
//
if (pDispParams->rgvarg[0].vt == VT_BSTR &&
m_dwSettings & REMOVE_POPUP_BY_TITLE)
{
m_pWebBrowser2->get_LocationURL(&bstrValue);
try
{
hr = pSurfManager.CreateInstance(__uuidof(SURFHELPLib::SurfManager));
bKill = pSurfManager->CheckTitle(
pDispParams->rgvarg[0].bstrVal, bstrValue);
if (bKill)
{
m_pWebBrowser2->Quit();
}
}
catch(_com_error &e)
{
dbgPrintf("%s: Check title failed! %s\r\n", APP_NAME,
(LPCTSTR)e.Description());
}
SysFreeString(bstrValue);
}
break;
case DISPID_QUIT:
ManageConnection(FALSE);
break;
default:
break;
}
return S_OK;
}
BOOL CSurfHelper::RandomReplaceString(LPWSTR pwzString, LPCWSTR szCommand,
BOOL bRegardCase, BOOL bSmart)
{
long lLen;
BOOL bChanged = FALSE;
BOOL bReplace;
LPWSTR pBuffer = pwzString;
LPWSTR pTemp;
LPWSTR pNextLess;
LPWSTR pNextGreater;
while (TRUE)
{
if (bRegardCase)
{
pBuffer = wcsstr(pBuffer, szCommand);
}
else
{
pBuffer = stristrW(pBuffer, szCommand);
}
if (pBuffer == NULL)
break;
bReplace = TRUE;
lLen = wcslen(szCommand);
if (bSmart)
{
pTemp = pBuffer + lLen;
pNextLess = wcschr(pTemp, L'<');
pNextGreater = wcschr(pTemp, L'>');
if (!(pNextGreater != NULL && pNextGreater < pNextLess))
{
bReplace = FALSE;
}
}
if (bReplace)
{
randomString(pBuffer, lLen);
}
pBuffer += lLen;
bChanged = TRUE;
}
return bChanged;
}
BOOL CSurfHelper::RemoveFlash(LPWSTR pwzString)
{
BOOL bChanged = FALSE;
BOOL bFound;
LPWSTR pBuffer = pwzString;
LPWSTR pObjectBegin;
LPWSTR pObjectEnd;
LPWSTR pTdBegin;
LPWSTR pTdEnd;
while ((pBuffer = stristrW(pBuffer, L".swf")) != NULL)
{
pBuffer += 4;
pObjectBegin = pwzString;
while ((pObjectBegin = stristrW(pObjectBegin, L"<OBJECT")) != NULL &&
(pObjectEnd = stristrW(pObjectBegin, L"</OBJECT>")) != NULL)
{
if (pBuffer <= pObjectBegin)
{
break;
}
pObjectEnd += 9;
if (pBuffer > pObjectBegin && pBuffer < pObjectEnd)
{
bFound = FALSE;
pTdBegin = pObjectBegin - 1;
while (pTdBegin >= pwzString)
{
if (*pTdBegin == L'<')
{
if (wcsnicmp(pTdBegin + 1, L"TD", 2) == 0)
{
bFound = TRUE;
break;
}
if (wcsnicmp(pTdBegin + 1, L"/TD>", 4) == 0)
{
break;
}
}
pTdBegin --;
}
if (bFound)
{
bFound = FALSE;
pTdEnd = pObjectEnd;
while (*pTdEnd != L'\0')
{
if (*pTdEnd == L'<')
{
if (wcsnicmp(pTdEnd + 1, L"TD", 2) == 0)
{
break;
}
if (wcsnicmp(pTdEnd + 1, L"/TD>", 4) == 0)
{
pTdEnd += 5;
bFound = TRUE;
break;
}
}
pTdEnd ++;
}
}
if (bFound)
{
pObjectBegin = pTdBegin;
pObjectEnd = pTdEnd;
}
_wcsnset(pObjectBegin, L' ', pObjectEnd - pObjectBegin);
pBuffer = pObjectEnd;
bChanged = TRUE;
break;
}
pObjectBegin = pObjectEnd;
}
}
return bChanged;
}
BOOL CSurfHelper::RemoveTimer(LPWSTR pwzString)
{
BOOL bChanged = FALSE;
LPWSTR pBuffer = pwzString;
LPWSTR pBegin;
LPWSTR pEnd;
while ((pBuffer = wcsstr(pBuffer, L"setTimeout")) != NULL)
{
pBuffer += 10;
pBegin = pBuffer;
while (iswspace(*pBegin))//skip white space
{
pBegin ++;
}
if (*pBegin != L'(')
{
continue;
}
pBegin ++;
while (iswspace(*pBegin))//skip white space
{
pBegin ++;
}
if (*pBegin == L'\"')
{
//find next \"
pBegin ++;
pEnd = pBegin;
while (*pEnd != L'\0' &&
(*pEnd != L'\"' || *(pEnd - 1) == L'\\'))
{
pEnd ++;
}
_wcsnset(pBegin, L' ', pEnd - pBegin);
}
else
{
//find ,
pEnd = pBegin;
while (*pEnd != L'\0' && *pEnd != L',')
{
pEnd ++;
}
*pBegin = L'\"';
pBegin++;
pEnd--;
*pEnd = L'\"';
if (pEnd > pBegin)
{
_wcsnset(pBegin, L' ', pEnd - pBegin);
}
}
bChanged = TRUE;
}
return bChanged;
}
void CSurfHelper::GetClientHeight(HWND hWnd, long* plClientHeight)
{
RECT rect;
POINT point;
GetClientRect(hWnd, &rect);
point.x = rect.left;
point.y = rect.top;
ClientToScreen(hWnd, &point);
rect.left = point.x;
rect.top = point.y;
point.x = rect.right;
point.y = rect.bottom;
ClientToScreen(hWnd, &point);
rect.right = point.x;
rect.bottom = point.y;
EnumChildWindows(hWnd, EnumChildProc, (LPARAM)&rect);
*plClientHeight = rect.bottom - rect.top;
}
BOOL CALLBACK EnumChildProc(HWND hwndChild, LPARAM lParam)
{
if (!IsWindowVisible(hwndChild))
{
return TRUE;
}
RECT rectChild;
LPRECT pRect = (LPRECT)lParam;
GetWindowRect(hwndChild, &rectChild);
if (rectChild.bottom == pRect->bottom &&
rectChild.top != pRect->top)//status bar
{
TCHAR szClassName[MAX_PATH];
GetClassName(hwndChild, szClassName, MAX_PATH);
if (_tcsstr(szClassName, _T("statusbar")) != NULL)
{
pRect->bottom = rectChild.top - 1;
}
}
else if (rectChild.bottom < pRect->bottom && rectChild.bottom >= pRect->top)
{
pRect->top = rectChild.bottom + 1;
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -