| 305 | } |
| 306 | |
| 307 | void GM_Manager::load() |
| 308 | { |
| 309 | QDir gmDir(m_settingsPath + QL1S("/greasemonkey")); |
| 310 | if (!gmDir.exists()) { |
| 311 | gmDir.mkdir(m_settingsPath + QL1S("/greasemonkey")); |
| 312 | } |
| 313 | |
| 314 | if (!gmDir.exists(QSL("requires"))) { |
| 315 | gmDir.mkdir(QSL("requires")); |
| 316 | } |
| 317 | |
| 318 | m_bootstrapScript = QzTools::readAllFileContents(QSL(":gm/data/bootstrap.min.js")); |
| 319 | m_valuesScript = QzTools::readAllFileContents(QSL(":gm/data/values.min.js")); |
| 320 | |
| 321 | QSettings settings(m_settingsPath + QL1S("/extensions.ini"), QSettings::IniFormat); |
| 322 | settings.beginGroup(QSL("GreaseMonkey")); |
| 323 | m_enabled = settings.value(QSL("enabled"), m_enabled).toBool(); |
| 324 | m_disabledScripts = settings.value(QSL("disabledScripts"), QStringList()).toStringList(); |
| 325 | settings.endGroup(); |
| 326 | |
| 327 | const auto fileNames = gmDir.entryList(QStringList(QSL("*.js")), QDir::Files); |
| 328 | for (const QString &fileName : fileNames) { |
| 329 | const QString absolutePath = gmDir.absoluteFilePath(fileName); |
| 330 | auto* script = new GM_Script(this, absolutePath); |
| 331 | |
| 332 | if (!script->isValid()) { |
| 333 | delete script; |
| 334 | continue; |
| 335 | } |
| 336 | |
| 337 | m_scripts.append(script); |
| 338 | |
| 339 | if (m_disabledScripts.contains(script->fullName())) { |
| 340 | script->setEnabled(false); |
| 341 | } |
| 342 | else if (script->startAt() == GM_Script::ContextMenu) { |
| 343 | m_contextMenuScripts.append(script); |
| 344 | } |
| 345 | else if (isEnabled()) { |
| 346 | mApp->webProfile()->scripts()->insert(script->webScript()); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | m_jsObject->setSettingsFile(m_settingsPath + QSL("/greasemonkey/values.ini")); |
| 351 | ExternalJsObject::registerExtraObject(QSL("greasemonkey"), m_jsObject); |
| 352 | } |
| 353 | |
| 354 | void GM_Manager::scriptChanged() |
| 355 | { |